filelib.h
Functions | |
Returns the standard directory path separator used on this platform. | |
Returns the standard search path separator used on this platform. | |
Returns the root of a filename.ext pair, which consists of everything in filename up to the last dot and the subsequent extension. | |
Returns the extension component of filename , which consists of the separating dot and all subsequent characters. | |
Returns all but the last component of a path name, where the components are names separated by any of the directory path separators (forward or reverse slashes). | |
Returns the last component of a path name, where the components are names separated by any of the directory path separators (forward or reverse slashes). | |
Adds an extension to a file name if none already exists. | |
Opens a files by searching directories in a search path for the first matching file. | |
Returns a canonical name of a file found using a search path. | |
Deletes the specified file. | |
Renames a file. | |
Returns true if the specified file exists. | |
Returns true if the specified file is a regular file. | |
Returns true if the specified file is a symbolic link. | |
Returns true if the specified file is a directory. | |
Creates a new directory for the specified pathname. | |
Creates a new directory for the specified pathname. | |
Changes the current directory to the specified path. | |
Returns an absolute pathname for the current directory. | |
Expands a pathname into a canonical name for the platform. | |
Returns an alphabetical list of all the files in the specified directory, excluding the unix . and .. entries. | |
Creates a new directory iterator that will step through the files in the specified directory. | |
Creates a new directory iterator that will walk recursively through the files in the specified directory and its subdirectories. | |
Determines whether the filename matches the specified pattern. | |
Gets the file type of a Macintosh file, which is a four-character string. | |
Gets the creator code of a Macintosh file, which is a four-character string. |
string getDirectoryPathSeparator(void);
Usage:
sep = getDirectoryPathSeparator();
string getSearchPathSeparator(void);
Usage:
sep = getSearchPathSeparator();
string getRoot(string filename);
filename.ext
pair, which
consists of everything in filename
up to the last dot and
the subsequent extension. If no dot appears, getRoot
returns the entire name.
the extension
Usage:
root = getRoot(filename);
string getExtension(string filename);
filename
, which
consists of the separating dot and all subsequent characters.
If no dot exists in the final component, extension
returns the empty string. Note that this interpretation is
different than one used by the :e
substitution in
the shell. The semantics were chosen so that the expression
concat(getRoot(filename), getExtension(filename))is equal to the original
filename
.
Usage:
ext = getExtension(filename);
string getHead(string pathname);
getHead("a/b") = "a" getHead("a") = "" getHead("/a") = "/" getHead("/") = "/"
Usage:
head = getHead(pathname);
string getTail(string pathname);
getTail("a/b") = "b" getTail("a") = "a" getTail("/a") = "a" getTail("/") = ""
Usage:
tail = getTail(pathname);
string defaultExtension(string filename, string ext);
extension
argument begins with a leading *
,
any existing extension in filename
is replaced by
ext
.
Usage:
newname = defaultExtension(filename, ext);
FILE *openOnPath(string path, string filename, string mode);
openOnPath
routine has
the same structure as fopen
in the standard library
and the filename and mode arguments are the same as in that
call. The path argument consists of a list of directories
which are prepended to the filename, unless the filename begins
with an absolute directory marker, such as /
or
~
. The directories in the search path may be
separated either by colons (Unix style) or semicolons (Windows
style). The openOnPath
function returns an open
stream to the indicated file, or NULL
, if no
existing file is found.
Usage:
FILE *file = openOnPath(path, filename, mode);
string findOnPath(string path, string filename);
findOnPath
function is similar to
openOnPath
, except that it returns the name of
the file instead of trying to open in. If no matching file
is found, findOnPath returns NULL
.
Usage:
pathname = findOnPath(path, filename);
void deleteFile(string filename);
error
in the implementation.
Usage:
deleteFile(filename);
void renameFile(string oldname, string newname);
error
in the implementation.
Usage:
renameFile(oldname, newname);
bool fileExists(string pathname);
true
if the specified file exists.
Usage:
if (fileExists(pathname)) . . .
bool isFile(string pathname);
true
if the specified file is a regular file.
Usage:
if (isFile(pathname)) . . .
bool isSymbolicLink(string pathname);
true
if the specified file is a symbolic link.
Usage:
if (isSymbolicLink(pathname)) . . .
bool isDirectory(string pathname);
true
if the specified file is a directory.
Usage:
if (isDirectory(pathname)) . . .
void createDirectory(string pathname);
createDirectory
function does not report an error if
the directory already exists. Unlike createDirectoryPath
,
createDirectory
does not create missing directories
along the path. If some component of pathname
does
not exist, this function signals an error.
Usage:
createDirectory(pathname);
void createDirectoryPath(string pathname);
Usage:
createDirectoryPath(pathname);
void setCurrentDirectory(string path);
Usage:
setCurrentDirectory(pathname);
string getCurrentDirectory(void);
Usage:
pathname = getCurrentDirectory();
string expandPathname(string filename);
Usage:
fullname = expandPathname(pathname);
string *listDirectory(string dir);
.
and ..
entries. The array is terminated with a NULL
entry.
Usage:
string array[] = listDirectory(dir);
Iterator newDirectoryIterator(string dir);
Usage:
foreach (name in newDirectoryIterator(dir)) . . .
Iterator newDirectoryTreeIterator(string dir);
Usage:
foreach (name in newDirectoryTreeIterator(dir)) . . .
bool matchFilenamePattern(string filename, string pattern);
? |
Matches any single character |
* |
Matches any sequence of characters |
[...] |
Matches any of the specified characters |
[^...] |
Matches any character except the specified ones |
The last two options allow a range of characters to be specified in the
form a-z
.
Usage:
if (matchFilenamePattern(filename, pattern)) . . .
string getFileType(string filename);
Usage:
type = getFileType(filename);
string getFileCreator(string filename);
Usage:
type = getFileCreator(filename);