Suggestion: file:is_directory
Raimo Niskanen
raimo@REDACTED
Mon Jun 17 08:54:26 CEST 2002
I'll put it on the list of things that I *might* be able to squeeze into
R9 to be released this autumn.
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
jhague@REDACTED wrote:
>
> 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:
>
> -include_lib("kernel/include/file.hrl").
>
> is_dir(Filename) ->
> {ok, Info} = file:read_file_info(Filename),
> Type = Info#file_info.type,
> case Type of
> directory -> true;
> _ -> false
> end.
>
> 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
> name.)
More information about the erlang-questions
mailing list