![]() ![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Home News Download Goals & Approach Documentation FAQ FXRex Screenshots Adie PathFinder FOX Calculator Projects FXPy FXRuby EiffelFox The FOX Hole Japanese Docs ![]() |
![]() Documentation: File Manipulation
File Manipulation Functions Almost all applications will eventually be faced with the need to manipulate file, and directories, and access the underlying operating system's file system. In FOX, a large collection of useful filename and directory name manipulation functions is provided with which you can perform these tasks easily. Moreover, th FOX file manipulations are aware of platform specific idiosyncracies, such as UNC under MS-Windows and escaping sequences under UNIX.
Finding Special Directories Certain directories in the file system are special, like the applications current working directory, the users home directory, and so on. FOX supplies the following functions for this purpose:
This function obtains the environment variable name from the environment. It returns the empty string if not found.
Returns the current user's home directory.
Returns the home directory of the named user, or the current user's home directory if the parameter user is empty.
Change the application's current working directory to path
Returns the current working directory of the application.
Change the application's current drive letter to prefix, where prefix is the drive letter, like "a:", "b:", and so on. This function of course has no effect on UNIX systems.
Returns the current drive letter of the application. This function of course has no effect on UNIX systems.
Returns the path along which the systems shell usually locates executable programs, or "$PATH". The returned path string is a sequence of directories separated by PATHLISTSEP.
Filename Manipulation Manipulating filenames is done with the following functions:
Return the directory part of file. Note that directory("/bla/bla/") yields "/bla/bla" and NOT "/bla". However, directory("/bla/bla") yields "/bla" as we expect!
Return name and extension part of file. Note that name("/bla/bla/") yields "" and NOT "bla". However, name("/bla/bla") yields "bla" as we expect.
Return title part of file. This is the name of the document with the directory part and the extension part removed.
Return extension part of file.
Strip the extension part of file.
Return the drive letter part of file. Of course, on UNIX systems this will return the empty string.
Expand meta-characters in file. On UNIX systems, "~" is expanded into the current user's home directory, "~user" into the given user's home directory, via getUserDirectory(). Also, "$VARIABLE", "${VARIABLE}", or "$(VARIABLE)" will be expanded into the environment variable VARIABLE, via getEnvironment(). On MS-Windows, environment variables of the form "%VARIABLE%" are expanded similarly.
Return the simplest pathname representation of file. The path will remain relative if it was relative, or absolute if it was absolute. Also, a trailing "/" will be preserved as this is important in other functions. For example, simplify("..//aaa/./bbb//../c/") yields "../aaa/c/".
Return the absolute path to the file, given the current working directory and drive letter.
Build the absolute path to the file, from the given base directory and file.
Return the path to file, relative to the current working directory.
Return the path to file, relative to the directory base.
Enquote file to make safe for shell. Normally, quotes are only generated when necessary, but if forcequotes is TRUE quotes are always generated regarless of necessity.
Dequote file to yield the original again.
Generate unique filename of the form "pathnameXXX.ext", where pathname.ext is the original input file, and XXX is a number, possibly empty, that makes the file unique.
Search pathlist for this file, return full path name for first occurrence. The pathlist is a PATHLISTSEP separated list of directories, such as returned by getExecPath.
Return path to directory above input directory file.
Obtaining information about files A number of functions are also available to obtain various kinds of information about files or directories:
Return true if file is an absolute pathname.
Return true if input file is a top-level directory.
Return true if input file is a file name.
Return true if input file is a link.
Return true if input file is a directory.
Return true if input file is readable.
Return true if input file is writable.
Return true if input file is executable.
Return true if owner has read-write-execute permissions.
Return true if owner has read permissions.
Return true if owner has write permissions.
Return true if owner has execute permissions.
Return true if group has read-write-execute permissions.
Return true if group has read permissions.
Return true if group has write permissions.
Return true if group has execute permissions.
Return true if others have read-write-execute permissions.
Return true if others have read permissions.
Return true if others have write permissions.
Return true if others have execute permissions.
Return true if the file sets the user id on execution.
Return true if the file sets the group id on execution.
Return true if the file has the sticky bit set.
Return owner name of file, if available; otherwise "user".
Return group name of file, if available; otherwise "group".
Return size of file in bytes
Return last modified time of file.
Return last accessed time of file.
Return create-time of file.
Return touched time of file.
Copying, Moving, Linking Files The following operations are available on files:
Create new directory path, with permissions set to mode.
Create new empty file, with permissions set to mode.
Concatenate srcfile1 and srcfile2 to a dstfile. If overwrite is true, then the operation fails if dstfile already exists. srcfile1 and srcfile2 should not be the same as dstfile.
Remove file or directory, recursively.
Copy srcfile to a dstfile, recursively if srcfile is a directory. If overwrite is true, then the operation fails if dstfile or a file inside dstfile already exists.
Move srcfile to a dstfile, recursively if srcfile is a directory. If overwrite is true, then the operation fails if dstfile or a file inside dstfile already exists. If srcfile and dstfile are on the same file system, the files are moved; if srcfile and dstfile are on different file systems, the files are copied and the original srcfile is removed only after all files have been copied successfully.
Link dstfile to srcfile. If overwrite is true, then the operation fails if dstfilealready exists. If srcfile and dstfile are on different filesystems, the operation will fail.
Make a symbolic link from dstfile to srcfile. If overwrite is true, then the operation fails if dstfilealready exists.
Return the destination of the symlink file.
Other File Operations Finally, some operations which don't fit in any easy categories:
Perform wildcard match of file against the pattern. The pattern may contain special wild-card characters:
List files matching pattern in the directory given by path. Returns the number of files in the string-array list which matched the pattern or satisfied the flag conditions. The flags parameter can be a combination of the following:
Return current time.
Convert filetime to date-string.
Convert file time to date-string as per strftime(3). Format characters supported by most systems are:
Return info of file as reported by system stat(2) function.
Return true if file exists.
Return true if file1 and file2 are identical, i.e. refer to the same inode.
Return the permissions of file.
Change the permission of file to mode.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |