[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.21.3.4 File stats

See also 11.6.3 File attibute utilities, for high-level APIs.

Function: file-exists? path
Function: file-is-regular? path
Function: file-is-directory? path
Returns true if path exists, is a regular file, or is a directory, respectively. The latter two returns false if path doesn't exist at all.

These functions are built on top of primitive system interfaces described below; I provide these for convenience and compatibility (STk has the same functions).

Builtin Class: <sys-stat>
An object that represents struct stat, attributes of an entry in the filesystem. It has the following read-only slots.

Instance Variable: <sys-stat> type
A symbol represents the type of the file.
regular a regular file
directory a directory
character a character device
block a block device
fifo a fifo
symlink a symbolic link
socket a socket
If the file type is none of the above, #f is returned.

Note: Some operating systems don't have the socket file type and returns fifo for socket files. Portable programs should check both possibilities to see if the given file is a socket.

Instance Variable: <sys-stat> perm
An exact integer for permission bits of struct stat. It is the same as lower 9-bits of "mode" slot; provided for the convenience.

Instance Variable: <sys-stat> mode
Instance Variable: <sys-stat> ino
Instance Variable: <sys-stat> dev
Instance Variable: <sys-stat> rdev
Instance Variable: <sys-stat> nlink
Instance Variable: <sys-stat> uid
Instance Variable: <sys-stat> gid
Instance Variable: <sys-stat> size
An exact integer for those information of struct stat.

Instance Variable: <sys-stat> atime
Instance Variable: <sys-stat> mtime
Instance Variable: <sys-stat> ctime
A number of seconds since Unix Epoch for those information of struct stat.

Function: sys-stat path
Function: sys-fstat port-or-fd
[POSIX] Returns a <sys-stat> object of path, or the underlying file of port-or-fd, which may be a port or a positive exact integer file descriptor, respectively.

If path is a symbolic link, a stat of the file the link points to is returned from sys-stat.

If port-or-fd is not associated to a file, sys-fstat returns #f.

Function: sys-lstat path
Like sys-stat, but it returns a stat of a symbolic link if path is a symbolic link.

 
gosh> (describe (sys-stat "gauche.h"))
#<<sys-stat> 0x815af70> is an instance of class <sys-stat>
slots:
  type      : regular
  perm      : 420
  mode      : 33188
  ino       : 845140
  dev       : 774
  rdev      : 0
  nlink     : 1
  uid       : 400
  gid       : 100
  size      : 79549
  atime     : 1020155914
  mtime     : 1020152005
  ctime     : 1020152005

Function: sys-stat->mode stat
Function: sys-stat->ino stat
Function: sys-stat->dev stat
Function: sys-stat->rdev stat
Function: sys-stat->nlink stat
Function: sys-stat->size stat
Function: sys-stat->uid stat
Function: sys-stat->gid stat
Function: sys-stat->atime stat
Function: sys-stat->mtime stat
Function: sys-stat->ctime stat
Function: sys-stat->file-type stat
Deprecated. Use slot-ref to access information of <sys-stat> object.

Function: sys-access pathname amode
[POSIX] An interface to access(2). Returns a boolean value of indicating whether access of pathname is allowed in amode. amode can be a combinations (logical or) of following predefined flags.
R_OK
Checks whether pathname is readable by the current user.
W_OK
Checks whether pathname is writable by the current user.
X_OK
Checks whether pathname is executable (or searchable in case pathname is a directory) by the current user.
F_OK
Checks whether pathname exists or not, regardless of the access permissions of pathname. (But you need to have access permissions of the directories containing pathname).

Function: sys-chmod path mode
Change the mode of the file named path to mode. mode must be a small positive integer whose lower 9 bits specifies POSIX style permission.

Function: sys-chown path owner-id group-id
Change the owner and/or group of the file named path to owner-id and group-id respectively. owner-id and group-id must be an exact integer. If either of them is -1, the corresponding ownership is not changed.

Function: sys-utime path &optional atime mtime
Change the file's access time and modification time to atime and mtime, respectively. If atime and mtime is omitted, they are set to the current time. See also touch-file (See section 11.6.4 File operations).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html