FileNames.mesa
This interface provides some utilities for manipulating file names and path names.
Last Edited by: Stewart.pa, December 13, 1983 6:44 pm
DIRECTORY
Rope USING [ROPE];
Useful procedures for using the file system.
Here are a collection of useful file-system related procedures.
FileWithSearchRules:
PROC [root: Rope.
ROPE, defaultExtension: Rope.
ROPE, requireExtension:
BOOL ←
TRUE, requireExact:
BOOL ←
TRUE, searchRules:
REF
ANY]
RETURNS [fullPath: Rope.
ROPE, ambiguous:
BOOL ←
FALSE];
FileWithSearchRules uses the working directory and the search rules to try to translate the short name of a file into a full path name. Calls ResolveRelativePath first. NIL is returned if the file cannot be found.
searchRules should either be a LIST OF REF ANY each of whose elements are Rope.ROPEs or a LIST OF Rope.ROPE.
If requireExtension, then if root has an extension, it must be the same as defaultExtension.
FileWithSearchRules adds !H to all pattern matches
IF requireExact = TRUE, then FileWithSearchRules will not try for a unique pattern match, but will only check exact names.
FileWithSearchRules returns NIL and ambiguous = TRUE if it finds more than one matching file.
FileNames returns not-NIL and ambiguous = TRUE if the result was found as a consequence of a unique pattern match.
FileWithSearchRules uses the following rules:
IF root is a full path name then {
tries root
tries Concat[root, defaultExtension]
IF NOT requireExact THEN tries for a unique match for Cat[root, *, defaultExtension]
}
ELSE {
tries root (automatically used $WorkingDirectory)
FOR wdir ← each element of search rules {
tries Concat[wdir, root]
}
tries Concat[root, defaultExtension] (automatically used $WorkingDirectory)
FOR wdir ← each element of search rules {
tries Cat[wdir, root, defaultExtension]
}
IF NOT requireExact THEN FOR wdir ← each element of search rules {
tries for a unique match for Cat[wdir, root, *, defaultExtension]
}
}
Returns NIL if can't find it.
ResolveRelativePath:
PROC [path: Rope.
ROPE]
RETURNS [Rope.
ROPE];
If path starts with ./ or ../, ResolveRelativePath converts it into the equivalent full path name using the $WorkingDirectory property on the process properties list.
If path = "." returns the current working directory.
If path = ".." returns the parent of the current working directory.
ConvertToSlashFormat:
PROC [path: Rope.
ROPE]
RETURNS [Rope.
ROPE];
Converts FS name strings to slash format, but makes no consistancy checks.
CurrentWorkingDirectory:
PROC
RETURNS [Rope.
ROPE];
Returns the currentworking directory, if there is one, otherwise returns the FS default working directory. Converts to slash format. (If any conversion was necessary, stores back the new version as the working directory.)
HomeDirectory:
PROC
RETURNS [Rope.
ROPE];
Returns the current user's directory. This will be something like ///Users/Stewart.pa/.
IsADirectory:
PROC [path: Rope.
ROPE]
RETURNS [
BOOL];
If the path ends in '/ or '>, or '], returns TRUE. Returns FALSE if the path is empty.
IsAPattern:
PROC [path: Rope.
ROPE]
RETURNS [
BOOL];
If the path contains a '*, returns TRUE.
GetShortName:
PROC [path: Rope.
ROPE, stripOffVersionNumber:
BOOL ←
TRUE]
RETURNS [Rope.
ROPE];
Returns the part of the path after the last '/, '>, or ']. (Strips off version number if stripOffVersionNumber is TRUE.)
Tail:
PROC [s: Rope.
ROPE, char:
CHAR]
RETURNS [Rope.
ROPE];
Tail returns the part of a rope after the last instance of char.
StripVersionNumber:
PROC [path: Rope.
ROPE]
RETURNS [Rope.
ROPE];
Returns the part of path before the '!, if any.
IsRemote:
PROC [path: Rope.
ROPE]
RETURNS [
BOOL];
Returns TRUE if the server part of path is not empty. If path is not a full path name, then IsRemote looks at the current working directory.
InASubdirectory:
PROC [parent: Rope.
ROPE, path: Rope.
ROPE]
RETURNS [
BOOL];
If parent is not a prefix of path returns FALSE. If parent is a prefix of path, returns TRUE only if the part of path after the prefix contains a '/ or '>.
FirstSubdirectory:
PROC [parent: Rope.
ROPE, path: Rope.
ROPE]
RETURNS [Rope.
ROPE];
If NOT InASubdirectory[parent, path] then returns NIL. Otherwise, returns the part of path up to and including the first '/ or '> after the end of parent.
DirectoryContaining:
PROC [path: Rope.
ROPE, pos:
INT]
RETURNS [Rope.
ROPE];
Return the prefix of the part of name before pos which is the name of a directory..
Directory:
PROC [path: Rope.
ROPE]
RETURNS [Rope.
ROPE];
Return the directory part of the path.