Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
filelib(3)		   Erlang Module Definition		    filelib(3)

       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" file names (i.e. files whose names
       do not comply with the expected encoding). Such files will  be  ignored
       by the functions	in this	module.

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

       filename() = file:name()

       dirname() = filename()

       dirname_all() = filename_all()

       filename_all() =	file:name_all()

       ensure_dir(Name)	-> ok |	{error,	Reason}


		 Name =	filename_all() | dirname_all()
		 Reason	= file:posix()

	      The  ensure_dir/1	 function  ensures that	all parent directories
	      for the given file or directory name Name	exist, trying to  cre-
	      ate them if necessary.

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

       file_size(Filename) -> integer()	>= 0


		 Filename = filename_all()

	      The file_size function returns the size of the given file.

       fold_files(Dir, RegExp, Recursive, Fun, AccIn) -> AccOut


		 Dir = dirname()
		 RegExp	= string()
		 Recursive = boolean()
		 Fun = fun((F :: file:filename(), AccIn) -> AccOut)
		 AccIn = AccOut	= term()

	      The fold_files/5 function	folds the function Fun over all	(regu-
	      lar) files F in the directory Dir	that match the regular expres-
	      sion  RegExp (see	the re module for a description	of the allowed
	      regular expressions). If Recursive is true  all  sub-directories
	      to Dir are processed. The	regular	expression matching is done on
	      just the filename	without	the directory part.

	      If Unicode file name translation is in effect and	the file  sys-
	      tem  is completely transparent, file names that cannot be	inter-
	      preted as	Unicode	may be encountered, in which  case  the	 fun()
	      must  be	prepared  to handle raw	file names (i.e. binaries). If
	      the regular expression contains codepoints beyond	255,  it  will
	      not match	file names that	do not conform to the expected charac-
	      ter encoding (i.e. are not encoded in valid UTF-8).

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

       is_dir(Name) -> boolean()


		 Name =	filename_all() | dirname_all()

	      The is_dir/1 function returns true if Name refers	 to  a	direc-
	      tory, and	false otherwise.

       is_file(Name) ->	boolean()


		 Name =	filename_all() | dirname_all()

	      The  is_file/1 function returns true if Name refers to a file or
	      a	directory, and false otherwise.

       is_regular(Name)	-> boolean()


		 Name =	filename_all()

	      The is_regular/1 function	returns	true if	Name refers to a  file
	      (regular file), and false	otherwise.

       last_modified(Name) -> file:date_time() | 0


		 Name =	filename_all() | dirname_all()

	      The last_modified/1 function returns the date and	time the given
	      file or directory	was last modified, or 0	if the file  does  not

       wildcard(Wildcard) -> [file:filename()]


		 Wildcard = filename() | dirname()

	      The  wildcard/1  function	returns	a list of all files that match
	      Unix-style wildcard-string Wildcard.

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

		  Matches one character.

		  Matches any number of	characters up to the end of the	 file-
		  name,	the next dot, or the next slash.

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

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

		  Alternation. Matches one of the alternatives.

	      Other characters represent themselves. Only filenames that  have
	      exactly  the  same  character  in	 the same position will	match.
	      (Matching	is case-sensitive; i.e.	"a" will not match "A").

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


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

	      To find all .beam	files in all applications, the following  line
	      can be used:


	      To find either .erl or .hrl in all applications src directories,
	      the following


	      or the following line


	      can be used.

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


	      To find all .erl or .hrl files in	either src or include directo-
	      ries, use:


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


       wildcard(Wildcard, Cwd) -> [file:filename()]


		 Wildcard = filename() | dirname()
		 Cwd = dirname()

	      The wildcard/2 function works like wildcard/1, except  that  in-
	      stead of the actual working directory, Cwd will be used.

Ericsson AB			  stdlib 2.4			    filelib(3)


Want to link to this manual page? Use this URL:

home | help