Suggestion: file:is_directory

Ulf Wiger etxuwig@REDACTED
Mon Jun 17 09:37:39 CEST 2002


On Sun, 16 Jun 2002 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.

I agree with James, and have also (via support@REDACTED I
believe) proposed the following, reasonably similar, addition:

- I don't know if it's just me, but I often find myself writing
- code like:
-
-
- foo(Dir) ->
-   {ok, Fs} = file:list_dir(Dir),
-   foo_1(Fs, Dir).
-
- foo_1([F|Fs], Dir) ->
-    File = filename:join(Dir, F),
-    case file:read_file_info(File) of
-       ...
-    end.
-
-
- It would seem like a function that combines list_dir() and
- read_file_info() in one function could save a lot of work +
- I/O.

One could imagine, for example, a function that returns
[{File, FileInfo}], and a file_info.erl module that provides
selector functions for a file_info record. This might be
interpreted as a step backwards by some, but I think the record
construct of today is not suited to be exported as part of the
interface (as is the case with the file_info record).

/Uffe

-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks





More information about the erlang-questions mailing list