Version: 5.3
File Utilities
by Erich Rast <erich ’at snafu.de>
1 Introduction
The File Utilities library is a collection of helper functions
for dealing with paths and files.
Note: Most of this library has been developed for older versions
of Racket. You should check if there is a built-in Racket library
function with the same functionality before using one from this library.
2 Function Reference
Returns the name part from a file or directory path.
If file-path is a already string, it is
returned without change, otherwise the name part
of the path is returned as by get-file-or-folder-name.
Returns the name part of a file or folder path without the suffix.
Returns the suffix part of a file or folder path. If there are multiple
suffixes, only the last one is returned. If no suffix is present,
an empty string is returned.
Composes a file name out of a main part name, a number,
and a suffix string. If the number part n is #f
then no number will be added to the name part.
Returns a name string that is guaranteed to be unique within folder.
Caution: This procedure creates neat file names such as "file-3.txt"
for a given name "file.txt" but does so at the cost of checking for
existing files with number suffixes 1, 2, ..., so for performance reasons you
ought not use this function to create many files with the same base and suffix
part within a folder.
Returns the parent directory of a folder or #f if there is none.
Returns a file or directory path that is unique within the parent directory of
suggested-path. The same performance caveat as for
make-unique-name applies.
Returns
#t if the two paths given likely point to the same location
in the file system,
#f otherwise. This method normalizes the
paths, but might yield false negatives under rare circumstances.
Use
file=? for a slower, but more reliable method to compar
e whether two paths point to the same file.
Returns #t if the two file paths alias the same file in the file system,
#f otherwise. This method requires read permissions on the files
and temporarily opens the files for reading. It cannot be used to compare
directories.
(move-directory-to/renaming | | source-directory | | | | | | | destination-directory) | | → | | path? |
|
source-directory : path? |
destination-directory : path? |
Moves the source directory into the destination directory, renaming it if it already exists at
the destination directory, and returns the possibly renamed path to the directory.
This method might fail with a filesystem exception if the source and
destination directories do not reside on the same volume.
(copy-directories/renaming | | source-directory | | | | | | | dest-directory | | | | | | | pred?) | | → | | void/c |
|
source-directory : path? |
dest-directory : path? |
pred? : (path? .->. boolean/c) |
Copy all files in the source directory for which pred? returns true into
the destination directory. If a file or directory with the same name already exists in
the destination directory, then the target file or folder is renamed by adding a
number to it before its suffix.
Returns #t if the file is visible according to Unix naming
conventions, #f otherwise. This function only checks whether the
file name starts with "." and might not correctly identify other types of
invisible files (e.g. on OS X).
Count the lines in the port. The port must support line counting or else an exception is raised.
(rename-or-copy-file source target) → void/c
|
source : path? |
target : path? |
Rename or copy the file at source to the path target.
This function also works accross volume boundaries, in case of which the file is copied
and then the original file is deleted.
(rename-or-copy-directory source target) → void/c
|
source : path? |
target : path? |
Rename or copy the directory at source to path target.
This function also works accross volume boundaries, in case of which the directory
and all files and subdirectories in it are copied first
and then the original directory and all files in it are deleted.
(rename-or-copy-file-or-directory | | source | | | | | | | target) | | → | | void/c |
|
source : path? |
target : path? |
Rename or copy a file or directory at source to path target.
This function also works accross volume boundaries, as described in the documentation of
rename-or-copy-file and rename-or-copy-directory.
Returns #t if the given files are byte-for-byte identical, #f otherwise.