error on file manipulation

Hakan Stenholm etxhste@REDACTED
Tue Dec 11 11:08:54 CET 2001


I ran this in R7B and got the same error:

{ok,Macs2} = file:open("test.erl",read).
{ok,<0.38.0>}
2> file:file_info(Macs2).
{error,einval}
3> file:read_file_info(Macs2).
{error,einval}

but this is wrong in several ways:

the format of open should be:
open(Filename, ModeList)

  Opens the file Filename in the mode determined by ModeList. ModeList may   
  contain one or more of the following items: 

  read  - The file, which must exist, is opened for reading. 
....

4> {ok,Macs3} = file:open("test.erl",[read]).
{ok,<0.42.0>}

file_info/1 is deprecated, use read_file_info/1 instead, also note that both
functions take filename and NOT an iodevice.

The documentation says:
read_file_info(Filename)

  Retrieves information about a file. Returns {ok, FileInfo} if successful,
  otherwise {error, Reason}. FileInfo is a record. Its definition can be found
  by including file.hrl from the kernel application: 

  -include_lib("kernel/include/file.hrl").
                
  The record contains the following fields. 
  ....

6> file:read_file_info("test.erl").
{ok,{file_info,383,
               regular,
               read_write,
               {{2001,12,11},{10,54,47}},
               {{2001,11,20},{13,59,24}},
               {{2001,11,20},{13,59,24}},
               33204,
               1,
               46137348,
               0,
               3796523,
               41013,
               862}}




More information about the erlang-questions mailing list