(guile.info.gz) File System
Info Catalog
(guile.info.gz) Ports and File Descriptors
(guile.info.gz) POSIX
(guile.info.gz) User Information
38.3 File System
================
These procedures allow querying and setting file system attributes
(such as owner, permissions, sizes and types of files); deleting,
copying, renaming and linking files; creating and removing directories
and querying their contents; syncing the file system and creating
special files.
-- Scheme Procedure: access? path how
-- C Function: scm_access (path, how)
Return `#t' if PATH corresponds to an existing file and the
current process has the type of access specified by HOW, otherwise
`#f'. HOW should be specified using the values of the variables
listed below. Multiple values can be combined using a bitwise or,
in which case `#t' will only be returned if all accesses are
granted.
Permissions are checked using the real id of the current process,
not the effective id, although it's the effective id which
determines whether the access would actually be granted.
-- Variable: R_OK
test for read permission.
-- Variable: W_OK
test for write permission.
-- Variable: X_OK
test for execute permission.
-- Variable: F_OK
test for existence of the file.
-- Scheme Procedure: stat object
-- C Function: scm_stat (object)
Return an object containing various information about the file
determined by OBJ. OBJ can be a string containing a file name or
a port or integer file descriptor which is open on a file (in
which case `fstat' is used as the underlying system call).
The object returned by `stat' can be passed as a single parameter
to the following procedures, all of which return integers:
`stat:dev'
The device containing the file.
`stat:ino'
The file serial number, which distinguishes this file from all
other files on the same device.
`stat:mode'
The mode of the file. This includes file type information and
the file permission bits. See `stat:type' and `stat:perms'
below.
`stat:nlink'
The number of hard links to the file.
`stat:uid'
The user ID of the file's owner.
`stat:gid'
The group ID of the file.
`stat:rdev'
Device ID; this entry is defined only for character or block
special files.
`stat:size'
The size of a regular file in bytes.
`stat:atime'
The last access time for the file.
`stat:mtime'
The last modification time for the file.
`stat:ctime'
The last modification time for the attributes of the file.
`stat:blksize'
The optimal block size for reading or writing the file, in
bytes.
`stat:blocks'
The amount of disk space that the file occupies measured in
units of 512 byte blocks.
In addition, the following procedures return the information from
stat:mode in a more convenient form:
`stat:type'
A symbol representing the type of file. Possible values are
regular, directory, symlink, block-special, char-special,
fifo, socket and unknown
`stat:perms'
An integer representing the access permission bits.
-- Scheme Procedure: lstat str
-- C Function: scm_lstat (str)
Similar to `stat', but does not follow symbolic links, i.e., it
will return information about a symbolic link itself, not the file
it points to. PATH must be a string.
-- Scheme Procedure: readlink path
-- C Function: scm_readlink (path)
Return the value of the symbolic link named by PATH (a string),
i.e., the file that the link points to.
-- Scheme Procedure: chown object owner group
-- C Function: scm_chown (object, owner, group)
Change the ownership and group of the file referred to by OBJECT to
the integer values OWNER and GROUP. OBJECT can be a string
containing a file name or, if the platform supports fchown, a port
or integer file descriptor which is open on the file. The return
value is unspecified.
If OBJECT is a symbolic link, either the ownership of the link or
the ownership of the referenced file will be changed depending on
the operating system (lchown is unsupported at present). If OWNER
or GROUP is specified as `-1', then that ID is not changed.
-- Scheme Procedure: chmod object mode
-- C Function: scm_chmod (object, mode)
Changes the permissions of the file referred to by OBJ. OBJ can
be a string containing a file name or a port or integer file
descriptor which is open on a file (in which case `fchmod' is used
as the underlying system call). MODE specifies the new
permissions as a decimal number, e.g., `(chmod "foo" #o755)'. The
return value is unspecified.
-- Scheme Procedure: utime pathname [actime [modtime]]
-- C Function: scm_utime (pathname, actime, modtime)
`utime' sets the access and modification times for the file named
by PATH. If ACTIME or MODTIME is not supplied, then the current
time is used. ACTIME and MODTIME must be integer time values as
returned by the `current-time' procedure.
(utime "foo" (- (current-time) 3600))
will set the access time to one hour in the past and the
modification time to the current time.
-- Scheme Procedure: delete-file str
-- C Function: scm_delete_file (str)
Deletes (or "unlinks") the file specified by PATH.
-- Scheme Procedure: copy-file oldfile newfile
-- C Function: scm_copy_file (oldfile, newfile)
Copy the file specified by PATH-FROM to PATH-TO. The return value
is unspecified.
-- Scheme Procedure: rename-file oldname newname
-- C Function: scm_rename (oldname, newname)
Renames the file specified by OLDNAME to NEWNAME. The return
value is unspecified.
-- Scheme Procedure: link oldpath newpath
-- C Function: scm_link (oldpath, newpath)
Creates a new name NEWPATH in the file system for the file named
by OLDPATH. If OLDPATH is a symbolic link, the link may or may
not be followed depending on the system.
-- Scheme Procedure: symlink oldpath newpath
-- C Function: scm_symlink (oldpath, newpath)
Create a symbolic link named PATH-TO with the value (i.e.,
pointing to) PATH-FROM. The return value is unspecified.
-- Scheme Procedure: mkdir path [mode]
-- C Function: scm_mkdir (path, mode)
Create a new directory named by PATH. If MODE is omitted then the
permissions of the directory file are set using the current umask.
Otherwise they are set to the decimal value specified with MODE.
The return value is unspecified.
-- Scheme Procedure: rmdir path
-- C Function: scm_rmdir (path)
Remove the existing directory named by PATH. The directory must
be empty for this to succeed. The return value is unspecified.
-- Scheme Procedure: opendir dirname
-- C Function: scm_opendir (dirname)
Open the directory specified by PATH and return a directory stream.
-- Scheme Procedure: directory-stream? obj
-- C Function: scm_directory_stream_p (obj)
Return a boolean indicating whether OBJECT is a directory stream
as returned by `opendir'.
-- Scheme Procedure: readdir port
-- C Function: scm_readdir (port)
Return (as a string) the next directory entry from the directory
stream STREAM. If there is no remaining entry to be read then the
end of file object is returned.
-- Scheme Procedure: rewinddir port
-- C Function: scm_rewinddir (port)
Reset the directory port STREAM so that the next call to `readdir'
will return the first directory entry.
-- Scheme Procedure: closedir port
-- C Function: scm_closedir (port)
Close the directory stream STREAM. The return value is
unspecified.
Here is an example showing how to display all the entries in a
directory:
(define dir (opendir "/usr/lib"))
(do ((entry (readdir dir) (readdir dir)))
((eof-object? entry))
(display entry)(newline))
(closedir dir)
-- Scheme Procedure: sync
-- C Function: scm_sync ()
Flush the operating system disk buffers. The return value is
unspecified.
-- Scheme Procedure: mknod path type perms dev
-- C Function: scm_mknod (path, type, perms, dev)
Creates a new special file, such as a file corresponding to a
device. PATH specifies the name of the file. TYPE should be one
of the following symbols: regular, directory, symlink,
block-special, char-special, fifo, or socket. PERMS (an integer)
specifies the file permissions. DEV (an integer) specifies which
device the special file refers to. Its exact interpretation
depends on the kind of special file being created.
E.g.,
(mknod "/dev/fd0" 'block-special #o660 (+ (* 2 256) 2))
The return value is unspecified.
-- Scheme Procedure: tmpnam
-- C Function: scm_tmpnam ()
Return a name in the file system that does not match any existing
file. However there is no guarantee that another process will not
create the file after `tmpnam' is called. Care should be taken if
opening the file, e.g., use the `O_EXCL' open flag or use
`mkstemp!' instead.
-- Scheme Procedure: mkstemp! tmpl
-- C Function: scm_mkstemp (tmpl)
Create a new unique file in the file system and returns a new
buffered port open for reading and writing to the file. TMPL is a
string specifying where the file should be created: it must end
with `XXXXXX' and will be changed in place to return the name of
the temporary file.
-- Scheme Procedure: dirname filename
-- C Function: scm_dirname (filename)
Return the directory name component of the file name FILENAME. If
FILENAME does not contain a directory component, `.' is returned.
-- Scheme Procedure: basename filename [suffix]
-- C Function: scm_basename (filename, suffix)
Return the base name of the file name FILENAME. The base name is
the file name without any directory components. If SUFFIX is
provided, and is equal to the end of BASENAME, it is removed also.
(basename "/tmp/test.xml" ".xml")
=> "test"
Info Catalog
(guile.info.gz) Ports and File Descriptors
(guile.info.gz) POSIX
(guile.info.gz) User Information
automatically generated byinfo2html