error on file manipulation

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

error on file manipulation

Hakan Stenholm
I ran this in R7B and got the same error:

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

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]).

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:

  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:

  The record contains the following fields.

6> file:read_file_info("test.erl").