(octave.info)Filesystem Utilities


Next: File Archiving Utilities Prev: Timing Utilities Up: System Utilities
Enter node , (file) or (file)node

36.2 Filesystem Utilities
=========================

Octave includes many utility functions for copying, moving, renaming,
and deleting files; for creating, reading, and deleting directories; for
retrieving status information on files; and for manipulating file and
path names.

 -- : movefile F1
 -- : movefile F1 F2
 -- : movefile F1 F2 f
 -- : movefile (F1)
 -- : movefile (F1, F2)
 -- : movefile (F1, F2, 'f')
 -- : [STATUS, MSG, MSGID] = movefile (...)
     Move the source file or directory F1 to the destination F2.

     The name F1 may contain globbing patterns, or may be a cell array
     of strings.  If F1 expands to multiple filenames, F2 must be a
     directory.

     If no destination F2 is specified then the destination is the
     present working directory.  If F2 is a filename then F1 is renamed
     to F2.

     When the force flag ’f’ is given any existing files will be
     overwritten without prompting.

     If successful, STATUS is 1, and MSG, MSGID are empty character
     strings ("").  Otherwise, STATUS is 0, MSG contains a
     system-dependent error message, and MSGID contains a unique message
     identifier.  Note that the status code is exactly opposite that of
     the ‘system’ command.

     See also: Note: rename, Note: copyfile,
     Note: unlink, Note: delete, *note glob:
     XREFglob.

 -- : rename OLD NEW
 -- : [ERR, MSG] = rename (OLD, NEW)
     Change the name of file OLD to NEW.

     If successful, ERR is 0 and MSG is an empty string.  Otherwise, ERR
     is nonzero and MSG contains a system-dependent error message.

     See also: Note: movefile, *note copyfile:
     XREFcopyfile, Note: ls, Note: dir.

 -- : copyfile F1 F2
 -- : copyfile F1 F2 f
 -- : copyfile (F1, F2)
 -- : copyfile (F1, F2, 'f')
 -- : [STATUS, MSG, MSGID] = copyfile (...)
     Copy the source file(s) or directory F1 to the destination F2.

     The name F1 may contain globbing patterns, or may be a cell array
     of strings.  If F1 expands to multiple filenames, F2 must be a
     directory.

     When the force flag ’f’ is given any existing files will be
     overwritten without prompting.

     If successful, STATUS is 1, and MSG, MSGID are empty character
     strings ("").  Otherwise, STATUS is 0, MSG contains a
     system-dependent error message, and MSGID contains a unique message
     identifier.  Note that the status code is exactly opposite that of
     the ‘system’ command.

     See also: Note: movefile, Note: rename,
     Note: unlink, Note: delete, *note glob:
     XREFglob.

 -- : [ERR, MSG] = unlink (FILE)
     Delete the file named FILE.

     If successful, ERR is 0 and MSG is an empty string.  Otherwise, ERR
     is nonzero and MSG contains a system-dependent error message.

     See also: Note: delete, Note: rmdir.

 -- : link OLD NEW
 -- : [ERR, MSG] = link (OLD, NEW)
     Create a new link (also known as a hard link) to an existing file.

     If successful, ERR is 0 and MSG is an empty string.  Otherwise, ERR
     is nonzero and MSG contains a system-dependent error message.

     See also: Note: symlink, Note: unlink,
     Note: readlink, Note: lstat.

 -- : symlink OLD NEW
 -- : [ERR, MSG] = symlink (OLD, NEW)
     Create a symbolic link NEW which contains the string OLD.

     If successful, ERR is 0 and MSG is an empty string.  Otherwise, ERR
     is nonzero and MSG contains a system-dependent error message.

     See also: Note: link, Note: unlink, Note:
     readlink, Note: lstat.

 -- : readlink SYMLINK
 -- : [RESULT, ERR, MSG] = readlink (SYMLINK)
     Read the value of the symbolic link SYMLINK.

     If successful, RESULT contains the contents of the symbolic link
     SYMLINK, ERR is 0, and MSG is an empty string.  Otherwise, ERR is
     nonzero and MSG contains a system-dependent error message.

     See also: Note: lstat, Note: symlink, Note:
     link, Note: unlink, Note: delete.

 -- : mkdir DIRNAME
 -- : mkdir PARENT DIRNAME
 -- : mkdir (DIRNAME)
 -- : mkdir (PARENT, DIRNAME)
 -- : [STATUS, MSG, MSGID] = mkdir (...)
     Create a directory named DIRNAME in the directory PARENT, creating
     any intermediate directories if necessary.

     If DIR is a relative path, and no PARENT directory is specified,
     then the present working directory is used.

     If successful, STATUS is 1, and MSG and MSGID are empty strings
     ("").  Otherwise, STATUS is 0, MSG contains a system-dependent
     error message, and MSGID contains a unique message identifier.

     When creating a directory permissions will be set to ‘0777 -
     UMASK’.

     See also: Note: rmdir, Note: pwd, *note cd:
     XREFcd, Note: umask.

 -- : rmdir DIR
 -- : rmdir (DIR, "s")
 -- : [STATUS, MSG, MSGID] = rmdir (...)
     Remove the directory named DIR.

     If the optional second parameter is supplied with value "s",
     recursively remove all subdirectories as well.

     If successful, STATUS is 1, and MSG, MSGID are empty character
     strings ("").  Otherwise, STATUS is 0, MSG contains a
     system-dependent error message, and MSGID contains a unique message
     identifier.

     See also: Note: mkdir, *note confirm_recursive_rmdir:
     XREFconfirm_recursive_rmdir, Note: pwd.

 -- : VAL = confirm_recursive_rmdir ()
 -- : OLD_VAL = confirm_recursive_rmdir (NEW_VAL)
 -- : confirm_recursive_rmdir (NEW_VAL, "local")
     Query or set the internal variable that controls whether Octave
     will ask for confirmation before recursively removing a directory
     tree.

     When called from inside a function with the "local" option, the
     variable is changed locally for the function and any subroutines it
     calls.  The original variable value is restored when exiting the
     function.

     See also: Note: rmdir.

 -- : ERR = mkfifo (NAME, MODE)
 -- : [ERR, MSG] = mkfifo (NAME, MODE)
     Create a FIFO special file named NAME with file mode MODE.

     MODE is interpreted as an octal number and is subject to umask
     processing.  The final calculated mode is ‘MODE - UMASK’.

     If successful, ERR is 0 and MSG is an empty string.  Otherwise, ERR
     is nonzero and MSG contains a system-dependent error message.

     See also: Note: pipe, Note: umask.

 -- : umask (MASK)
     Set the permission mask for file creation.

     The parameter MASK is an integer, interpreted as an octal number.

     If successful, returns the previous value of the mask (as an
     integer to be interpreted as an octal number); otherwise an error
     message is printed.

     The permission mask is a UNIX concept used when creating new
     objects on a file system such as files, directories, or named
     FIFOs.  The object to be created has base permissions in an octal
     number MODE which are modified according to the octal value of
     MASK.  The final permissions for the new object are ‘MODE - MASK’.

     See also: Note: fopen, Note: mkdir, Note:
     mkfifo.

 -- : [INFO, ERR, MSG] = stat (FILE)
 -- : [INFO, ERR, MSG] = stat (FID)
 -- : [INFO, ERR, MSG] = lstat (FILE)
 -- : [INFO, ERR, MSG] = lstat (FID)
     Return a structure INFO containing the following information about
     FILE or file identifier FID.

     ‘dev’
          ID of device containing a directory entry for this file.

     ‘ino’
          File number of the file.

     ‘mode’
          File mode, as an integer.  Use the functions ‘S_ISREG’,
          ‘S_ISDIR’, ‘S_ISCHR’, ‘S_ISBLK’, ‘S_ISFIFO’, ‘S_ISLNK’, or
          ‘S_ISSOCK’ to extract information from this value.

     ‘modestr’
          File mode, as a string of ten letters or dashes as would be
          returned by ‘ls -l’.

     ‘nlink’
          Number of links.

     ‘uid’
          User ID of file’s owner.

     ‘gid’
          Group ID of file’s group.

     ‘rdev’
          ID of device for block or character special files.

     ‘size’
          Size in bytes.

     ‘atime’
          Time of last access in the same form as time values returned
          from ‘time’.  Note: Timing Utilities.

     ‘mtime’
          Time of last modification in the same form as time values
          returned from ‘time’.  Note: Timing Utilities.

     ‘ctime’
          Time of last file status change in the same form as time
          values returned from ‘time’.  Note: Timing Utilities.

     ‘blksize’
          Size of blocks in the file.

     ‘blocks’
          Number of blocks allocated for file.

     If the call is successful ERR is 0 and MSG is an empty string.  If
     the file does not exist, or some other error occurs, INFO is an
     empty matrix, ERR is −1, and MSG contains the corresponding system
     error message.

     If FILE is a symbolic link, ‘stat’ will return information about
     the actual file that is referenced by the link.  Use ‘lstat’ if you
     want information about the symbolic link itself.

     For example:

          [info, err, msg] = stat ("/vmlinuz")
            ⇒ info =
               {
                 atime = 855399756
                 rdev = 0
                 ctime = 847219094
                 uid = 0
                 size = 389218
                 blksize = 4096
                 mtime = 847219094
                 gid = 6
                 nlink = 1
                 blocks = 768
                 mode = -rw-r--r--
                 modestr = -rw-r--r--
                 ino = 9316
                 dev = 2049
               }
            ⇒ err = 0
            ⇒ msg =

     See also: Note: lstat, Note: ls, *note dir:
     XREFdir.

 -- : S_ISBLK (MODE)
     Return true if MODE corresponds to a block device.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : S_ISCHR (MODE)
     Return true if MODE corresponds to a character device.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : S_ISDIR (MODE)
     Return true if MODE corresponds to a directory.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : S_ISFIFO (MODE)
     Return true if MODE corresponds to a fifo.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : S_ISLNK (MODE)
     Return true if MODE corresponds to a symbolic link.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : S_ISREG (MODE)
     Return true if MODE corresponds to a regular file.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : S_ISSOCK (MODE)
     Return true if MODE corresponds to a socket.

     The value of MODE is assumed to be returned from a call to ‘stat’.

     See also: Note: stat, Note: lstat.

 -- : fileattrib (FILE)
 -- : fileattrib ()
 -- : [STATUS, MSG, MSGID] = fileattrib (...)
     Return information about FILE.

     If successful, STATUS is 1 and MSG is a structure with the
     following fields:

     ‘Name’
          Full name of FILE.

     ‘archive’
          True if FILE is an archive (Windows).

     ‘system’
          True if FILE is a system file (Windows).

     ‘hidden’
          True if FILE is a hidden file (Windows).

     ‘directory’
          True if FILE is a directory.

     ‘UserRead’
     ‘GroupRead’
     ‘OtherRead’
          True if the user (group; other users) has read permission for
          FILE.

     ‘UserWrite’
     ‘GroupWrite’
     ‘OtherWrite’
          True if the user (group; other users) has write permission for
          FILE.

     ‘UserExecute’
     ‘GroupExecute’
     ‘OtherExecute’
          True if the user (group; other users) has execute permission
          for FILE.

     If an attribute does not apply (i.e., archive on a Unix system)
     then the field is set to NaN.

     If ‘attrib’ fails, MSG is a non-empty string containing an error
     message and MSG_ID is the non-empty string "fileattrib".

     With no input arguments, return information about the current
     directory.

     If FILE contains globbing characters, return information about all
     the matching files.

     See also: Note: glob.

 -- : isdir (F)
     Return true if F is a directory.

     See also: Note: exist, Note: stat, Note:
     is_absolute_filename, Note:
     is_rooted_relative_filename.

 -- : FILES = readdir (DIR)
 -- : [FILES, ERR, MSG] = readdir (DIR)
     Return the names of files in the directory DIR as a cell array of
     strings.

     If an error occurs, return an empty cell array in FILES.  If
     successful, ERR is 0 and MSG is an empty string.  Otherwise, ERR is
     nonzero and MSG contains a system-dependent error message.

     See also: Note: ls, Note: dir, *note glob:
     XREFglob, Note: what.

 -- : glob (PATTERN)
     Given an array of pattern strings (as a char array or a cell array)
     in PATTERN, return a cell array of filenames that match any of
     them, or an empty cell array if no patterns match.

     The pattern strings are interpreted as filename globbing patterns
     (as they are used by Unix shells).

     Within a pattern

     ‘*’
          matches any string, including the null string,

     ‘?’
          matches any single character, and

     ‘[...]’
          matches any of the enclosed characters.

     Tilde expansion is performed on each of the patterns before looking
     for matching filenames.  For example:

          ls
             ⇒
                file1  file2  file3  myfile1 myfile1b
          glob ("*file1")
             ⇒
                {
                  [1,1] = file1
                  [2,1] = myfile1
                }
          glob ("myfile?")
             ⇒
                {
                  [1,1] = myfile1
                }
          glob ("file[12]")
             ⇒
                {
                  [1,1] = file1
                  [2,1] = file2
                }

     See also: Note: ls, Note: dir, *note readdir:
     XREFreaddir, Note: what.

 -- : file_in_path (PATH, FILE)
 -- : file_in_path (PATH, FILE, "all")
     Return the absolute name of FILE if it can be found in PATH.

     The value of PATH should be a colon-separated list of directories
     in the format described for ‘path’.  If no file is found, return an
     empty character string.  For example:

          file_in_path (EXEC_PATH, "sh")
               ⇒ "/bin/sh"

     If the second argument is a cell array of strings, search each
     directory of the path for element of the cell array and return the
     first that matches.

     If the third optional argument "all" is supplied, return a cell
     array containing the list of all files that have the same name in
     the path.  If no files are found, return an empty cell array.

     See also: Note: file_in_loadpath, Note:
     dir_in_loadpath, Note: path.

 -- : filesep ()
 -- : filesep ("all")
     Return the system-dependent character used to separate directory
     names.

     If "all" is given, the function returns all valid file separators
     in the form of a string.  The list of file separators is
     system-dependent.  It is ‘/’ (forward slash) under UNIX or
     Mac OS X, ‘/’ and ‘\’ (forward and backward slashes) under Windows.

     See also: Note: pathsep.

 -- : [DIR, NAME, EXT] = fileparts (FILENAME)
     Return the directory, name, and extension components of FILENAME.

     The input FILENAME is a string which is parsed.  There is no
     attempt to check whether the filename or directory specified
     actually exists.

     See also: Note: fullfile, Note: filesep.

 -- : FILENAME = fullfile (DIR1, DIR2, ..., FILE)
 -- : FILENAMES = fullfile (..., FILES)
     Build complete filename from separate parts.

     Joins any number of path components intelligently.  The return
     value is the concatenation of each component with exactly one file
     separator between each non empty part and at most one leading
     and/or trailing file separator.

     If the last component part is a cell array, returns a cell array of
     filepaths, one for each element in the last component, e.g.:

          fullfile ("/home/username", "data", {"f1.csv", "f2.csv", "f3.csv"})
          ⇒  /home/username/data/f1.csv
              /home/username/data/f2.csv
              /home/username/data/f3.csv

     On Windows systems, while forward slash file separators do work,
     they are replaced by backslashes; in addition drive letters are
     stripped of leading file separators to obtain a valid file path.

     Note: ‘fullfile’ does not perform any validation of the resulting
     full filename.

     See also: Note: fileparts, *note filesep:
     XREFfilesep.

 -- : tilde_expand (STRING)
 -- : tilde_expand (CELLSTR)
     Perform tilde expansion on STRING.

     If STRING begins with a tilde character, (‘~’), all of the
     characters preceding the first slash (or all characters, if there
     is no slash) are treated as a possible user name, and the tilde and
     the following characters up to the slash are replaced by the home
     directory of the named user.  If the tilde is followed immediately
     by a slash, the tilde is replaced by the home directory of the user
     running Octave.

     If the input is a cell array of strings CELLSTR then tilde
     expansion is performed on each string element.

     Examples:

          tilde_expand ("~joeuser/bin")
               ⇒ "/home/joeuser/bin"
          tilde_expand ("~/bin")
               ⇒ "/home/jwe/bin"

 -- : [CNAME, STATUS, MSG] = canonicalize_file_name (FNAME)
     Return the canonical name of file FNAME.

     If the file does not exist the empty string ("") is returned.

     See also: Note: make_absolute_filename,
     Note: is_absolute_filename, Note:
     is_rooted_relative_filename.

 -- : make_absolute_filename (FILE)
     Return the full name of FILE beginning from the root of the file
     system.

     No check is done for the existence of FILE.

     See also: Note: canonicalize_file_name,
     Note: is_absolute_filename, Note:
     is_rooted_relative_filename, Note:
     isdir.

 -- : is_absolute_filename (FILE)
     Return true if FILE is an absolute filename.

     See also: *note is_rooted_relative_filename:
     XREFis_rooted_relative_filename, *note make_absolute_filename:
     XREFmake_absolute_filename, Note: isdir.

 -- : is_rooted_relative_filename (FILE)
     Return true if FILE is a rooted-relative filename.

     See also: Note: is_absolute_filename,
     Note: make_absolute_filename, Note:
     isdir.

 -- : VAL = recycle ()
 -- : OLD_VAL = recycle (NEW_VAL)
     Query or set the preference for recycling deleted files.

     When recycling is enabled, commands which would permanently erase
     files instead move them to a temporary location (such as the
     directory labeled Trash).

     Programming Note: This function is provided for MATLAB
     compatibility, but recycling is not implemented in Octave.  To help
     avoid accidental data loss an error will be raised if an attempt is
     made to enable file recycling.

     See also: Note: delete, Note: rmdir.


automatically generated by info2www version 1.2.2.9