20032018 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. filelib Bjorn Gustavsson Bjorn Gustavsson 1 Kenneth Lundin 2003-01-21 A filelib.xml
filelib File utilities, such as wildcard matching of filenames.

This module contains utilities on a higher level than the file module.

This module does not support "raw" filenames (that is, files whose names do not comply with the expected encoding). Such files are ignored by the functions in this module.

For more information about raw filenames, see the file module.

Ensure that all parent directories for a file or directory exist.

Ensures that all parent directories for the specified file or directory name Name exist, trying to create them if necessary.

Returns ok if all parent directories already exist or can be created. Returns {error, Reason} if some parent directory does not exist and cannot be created.

Return the size in bytes of a file.

Returns the size of the specified file.

Fold over all files matching a regular expression.

Folds function Fun over all (regular) files F in directory Dir that match the regular expression RegExp (for a description of the allowed regular expressions, see the re module). If Recursive is true, all subdirectories to Dir are processed. The regular expression matching is only done on the filename without the directory part.

If Unicode filename translation is in effect and the file system is transparent, filenames that cannot be interpreted as Unicode can be encountered, in which case the fun() must be prepared to handle raw filenames (that is, binaries). If the regular expression contains codepoints > 255, it does not match filenames that do not conform to the expected character encoding (that is, are not encoded in valid UTF-8).

For more information about raw filenames, see the file module.

Test whether Name refers to a directory.

Returns true if Name refers to a directory, otherwise false.

Test whether Name refers to a file or directory.

Returns true if Name refers to a file or a directory, otherwise false.

Test whether Name refers to a (regular) file.

Returns true if Name refers to a (regular) file, otherwise false.

Return the local date and time when a file was last modified.

Returns the date and time the specified file or directory was last modified, or 0 if the file does not exist.

Match filenames using Unix-style wildcards.

Returns a list of all files that match Unix-style wildcard string Wildcard.

The wildcard string looks like an ordinary filename, except that the following "wildcard characters" are interpreted in a special way:

?

Matches one character.

*

Matches any number of characters up to the end of the filename, the next dot, or the next slash.

**

Two adjacent * used as a single pattern match all files and zero or more directories and subdirectories.

[Character1,Character2,...]

Matches any of the characters listed. Two characters separated by a hyphen match a range of characters. Example: [A-Z] matches any uppercase letter.

{Item,...}

Alternation. Matches one of the alternatives.

Other characters represent themselves. Only filenames that have exactly the same character in the same position match. Matching is case-sensitive, for example, "a" does not match "A".

Notice that multiple "*" characters are allowed (as in Unix wildcards, but opposed to Windows/DOS wildcards).

Examples:

The following examples assume that the current directory is the top of an Erlang/OTP installation.

To find all .beam files in all applications, use the following line:

filelib:wildcard("lib/*/ebin/*.beam").

To find .erl or .hrl in all applications src directories, use either of the following lines:

filelib:wildcard("lib/*/src/*.?rl") filelib:wildcard("lib/*/src/*.{erl,hrl}")

To find all .hrl files in src or include directories:

filelib:wildcard("lib/*/{src,include}/*.hrl").

To find all .erl or .hrl files in either src or include directories:

filelib:wildcard("lib/*/{src,include}/*.{erl,hrl}")

To find all .erl or .hrl files in any subdirectory:

filelib:wildcard("lib/**/*.{erl,hrl}")
Match filenames using Unix-style wildcards starting at a specified directory.

Same as wildcard/1, except that Cwd is used instead of the working directory.

Find a file relative to a given directory.

Looks for a file of the given name by applying suffix rules to the given directory path. For example, a rule {"ebin", "src"} means that if the directory path ends with "ebin", the corresponding path ending in "src" should be searched.

If Rules is left out or is an empty list, the default system rules are used. See also the Kernel application parameter source_search_rules.

Find the source file for a given object file.

Equivalent to find_source(Base, Dir), where Dir is filename:dirname(FilePath) and Base is filename:basename(FilePath).

Find a source file relative to a given directory.

Applies file extension specific rules to find the source file for a given object file relative to the object directory. For example, for a file with the extension .beam, the default rule is to look for a file with a corresponding extension .erl by replacing the suffix "ebin" of the object directory path with "src" or "src/*". The file search is done through find_file/3. The directory of the object file is always tried before any other directory specified by the rules.

If Rules is left out or is an empty list, the default system rules are used. See also the Kernel application parameter source_search_rules.