[ Operating System | Reference Manual | Alphabetic Index ]

get_file_info(+File, ?Attr, -Value)

Succeeds if the file File (with absolute or relative pathname) exists and the value of its attribute Attr unfies with Value.
File
Atom or string.
Attr
Atom or variable.
Value
Constant or variable.

Description

This predicate is used to test the properties of a specified file. If Attr specifies one of the attributes listed below, then Value is unified with the attribute value on return. If Attr is a variable, the predicate on backtracking returns all attribute-value pairs that are relevant for the given file.

The possible attributes and their meanings are:

    Attribute  Type        Meaning
   ---------------------------------------------------------
    mode       integer     file mode (see table below)
    size       integer     file size in bytes
    type       atom        file type: file,directory,link,socket,
                           fifo,char_device or block_device

    device     integer     device number
    inode      integer     inode number (Unix)
    nlink      integer     number of links (Unix)
    uid        integer     user ID of the owner (Unix)
    uname      string      user name of the owner (Unix)
    gid        integer     group ID of the owner (Unix)
    gname      string      group name of the owner (Unix)

    atime      integer     time of last access
    mtime      integer     time of last data modification
    ctime      integer     time of last status change
    adate      string      date of last access (text)
    mdate      string      date of last data modification (text)
    cdate      string      date of last status change (text)

    readable   on/off      file is/isn't readable by this process
    writable   on/off      file is/isn't writable by this process
    executable on/off      file is/isn't executable by this process
The *name attributes are string representation of the corresponding *id attributes. The *date attributes are string representation of the corresponding *time attributes. The time for the *time attributes is measured as seconds elapsed since 00:00:00 GMT, Jan 1, 1970.

The flags readable, writable and executable indicate whether the running ECLiPSe process has the corresponding permissions on the file. Note that the executable permission for Windows may be approximate, because Windows (especially Vista) has a different system for dealing with execute permission.

The use of the 'mode' attribute and the following numbers is deprecated in favour of the 'type', 'readable', 'writable' and 'executable' attributes. The meaning of the bits in the mode attribute is as follows:

 Mode     Meaning
------------------------------------------------
 8'170000 file type
 8'040000 directory
 8'020000 character special
 8'060000 block special
 8'100000 normal file
 8'120000 symbolic link
 8'140000 socket
------------------------------------------------
 8'004000 set user ID on execution
 8'002000 set group ID on execution
------------------------------------------------
 8'000700 owner access
 8'000400 read permission for owner
 8'000200 write permission for owner
------------------------------------------------
 8'000070 group access
 8'000040 read permission for group
 8'000020 write permission for group
------------------------------------------------
 8'000007 other access
 8'000004 read permission for others
 8'000002 write permission for others
 8'000001 execute/search permission for others

Modes and Determinism

Fail Conditions

Fails if the file File does not exist, or doesn't have the attribute Attr

Exceptions

(4) instantiation fault
File is not instantiated.
(5) type error
File is neither an atom nor a string.
(5) type error
Attr is instantiated but not to an atom.
(5) type error
Value is instantiated but not to a constant.

Examples

Success:
   is_directory(File) :-
        get_file_info(File, type, directory),


   % the same test via mode bits:
   is_directory(File) :-
        get_file_info(File, mode, Mode),
        Mode /\ file_type =:= directory_flag.

   file_type(8'170000).
   directory_flag(8'40000).


   % A file is younger if its time is greater
   is_younger(File1, File2) :-
        get_file_info(File1, mtime) > get_file_info(File2, mtime).

Fail:
   get_file_info(nofile, mode, Mode).
   get_file_info('/', mode, 8'100000).

Error:
   get_file_info(File, ctime, T).                (Error 4).
   get_file_info([file], gid, G).                (Error 5).
   get_file_info(file, 1, X).                    (Error 5).



See Also

exists / 1, delete / 1, exec / 3, local_time / 8, local_time_string / 3