Suggestion: file:is_directory

Mon Jun 17 04:50:42 CEST 2002

I'm finding Erlang to be a great scripting language for things that 
I'd normally use Perl for.  One little addition to the file module 
that would be nice is file:is_dir/1.  file:list_dir/1 is great for 
getting a list of files in a directory, but then to figure out which 
of those are directories and not files themselves is verbose compared 
with Perl:


is_dir(Filename) ->
	{ok, Info} = file:read_file_info(Filename),
	Type = Info#file_info.type,
	case Type of
		directory -> true;
		_ -> false

Having to bring in the hrl file is doubly ugly; I always have to look 
it up in the docs.  And it's silly to create an entire file_info 
record just to make this check.  This is very common when doing a 
recursive traversal of a directory tree.

I could probably make a case for file:size and file:exists shortcuts 
as well :)

(BTW, the R8 docs for file:read_file_info neglect to give the name of 
the file_info record.  You have to look in the hrl file to find the 

More information about the erlang-questions mailing list