Miscellaneous procedures and functions for manipulating files and filenames
CompareFileNames
- compares two file names to see whether they are equal
Returns zero if files are equal, or the index of differences, or the difference in length if filenames are not equal
First filename
Second filename
ResolveLinks
- if True, searches through links to find the actual file for comparison
Length of first filename
Length of second filename
Checks whether an absolute file name is given in TheFileName

Checks whether an absolute file name is given in TheFileName

Makes use of FilenameIsWinAbsolute on Windows systems, otherwise uses FilenameIsUnixAbsolute

Returns True if an absolute filename has been supplied
The name of the file to be checked
FilenameIsWinAbsolute
- checks that the supplied name is an absolute file name for the Windows system

FilenameIsWinAbsolute - checks that the supplied name is an absolute file name for the Windows system

Looks, for instance, for Drive Letters and colon at the beginning of the string

Returns True if this is a true absolite Windows filename
The name of the file for checking
FilenameIsUnixAbsolute
- checks that the supplied name is an absolute filename in Unix systems

FilenameIsUnixAbsolute - checks that the supplied name is an absolute filename in Unix systems

Checks that the name is non-empty and starts with a slash

Returns True if the supplied name is a correct Absolute file name for a Unix system
The name of the file for checking
CheckIfFileIsExecutable
- creates Exception if file is not Executable

CheckIfFileIsExecutable - creates Exception if file is not Executable

Otherwise, there is no action

An exception is raised if the file is not executable
AFileName
- name of the file for checking
CheckIfFileIsSymlink
- raises an exception if file is not a Symbolic Link

CheckIfFileIsSymlink - raises an exception if file is not a Symbolic Link

Otherwise no action

An exception is raised with appropriate message if file does not exist or is not a correct symbolic link (eg dangling link, circular link, read access denied, or not a symbolic link)
AFileName
- name of file for checking
FileIsReadable
- checks whether supplied file name refers to a readable file

FileIsReadable - checks whether supplied file name refers to a readable file

Always true on Windows systems.

On Unix systems, checks permissions of file

Always true in Windows; in Unix systems, returns true if read permission exists for the file
Name of the file for checking
FileIsWritable
- checks if the supplied file name refers to a file that is writable

FileIsWritable - checks if the supplied file name refers to a file that is writable

Checks file permissions in both Unix and Windows systems

Returns True if Write permission exists
The name of the file for checking
FileIsText
- checks whether the supplied file name refers to a readable text file

FileIsText - checks whether the supplied file name refers to a readable text file

Searches the opening section of the file (first 1024 characters) for non-text characters such as ASCII 0 to 31 (except CR and LF, the new line characters)

If there is a file reading error, an Exception is raised and FileReadable returns False
Returns True if the file is a text file
The name of the file for checking
Returns false if a file reading Exception is encountered
FileIsExecutable
- checks if

AFileName
refers to an executable file

FileIsExecutable - checks if

AFileName refers to an executable file

On Windows systems, if the file exists it is regarded as executable.

On other systems (eg Unix etc), looks at file permissions to see whether execute flag is set

Returns True if file is executable (always true in Windows if file exists)
Name of the file for checking
FileIsSymLink
- check if file name is a symbolic link

FileIsSymLink - check if file name is a symbolic link

On Windows systems, always returns false. On others, returns true if it is a symbolic link

Returns True if file name is a symbolic link (always false in Windows systems)
Name of the file for checking
FileSize
- finds the size of the named file
Returns the size of the file, or -1 if not there
The name of the file for checking
GetFileDescription
- finds the Unix-type file description for the given file

GetFileDescription - finds the Unix-type file description for the given file

No action in Windows systems (returns empty string)

Returns empty string (Windows) or Unix-type file description string in other systems
The name of the file whose description is sought
ReadAllLinks
- tries to find the file that is referred to by the symbolic link in

FileName

ReadAllLinks - tries to find the file that is referred to by the symbolic link in

FileName

No function in Windows systems
On Unix-like systems, finds the linked file and returns its full path and filename, or (if ExceptionOnError has been set True) an Exception is raised with appropriate error message
If an error is encountered on trying to read the link, provided ExceptionOnError has been set True an Exception is raised with appropriate error message. Otherwise an error results in the return of an empty string.
Returns the full path and filename of the target file; empty if the file is not found, or the original FileName on Windows systems
The string containing the symbolic link
If True, an Exception is raised on encountering a file error
Checks if the given directory path exists
Returns True if the given directory path exists
Name of the directory path to be checked
ForceDirectory
- creates a directory if none exists
Returns True if successfully created directory
The name of the directory required
DeleteDirectory
- Delete the named directory (or only its contents if

OnlyChilds
is True)
If there was an error, such as trying to removing . or .., or there were insufficient permissions, or the file did not exist, False is returned
Returns True if the directory or its contents were correctly removed
The name of the directory for processing
If True, only the contents ('children') of the directory are removed
ProgramDirectory
- returns the directory in which the currently running program resides
Returns the name of the directory in which the current program is found
DirectoryIsWritable
- checks if it is possible to write a file to the named directory

DirectoryIsWritable - checks if it is possible to write a file to the named directory

Tries to create a text file within the named directory, and write to it. Returns True if it works, and False if it doesn't. Also raises an Exception on failure

An Exception is raised on failure to create or write to the temporary file
Returns True if successful in writing a temporary file to the named directory
Name of the Directory for checking
PascalFileExt
- typically '.pas', '.pp' or '.p'
ExtractFileNameOnly
- removes all path delimiters and file extensions, leaving just the file name
Returns the original file name with path delimiters and the extension removed
The name of the file for processing
ExtractFileNameWithoutExt
- returns just the name of the file without an extension
Returns the original file name if it had no extension, otherwise returns the file name with its extension removed
The name of the file for checking
CompareFileExt
- see whether the nominated file has an extension that is the same as the supplied extension
Returns zero if extension is present in file name, otherwise returns non-zero value
The FileName whose extension is to be checked
Ext
- string defining the Extension to be checked
CaseSensitive
- if True, case of

Ext
must match case in

FileName
FilenameIsPascalUnit
- checks that the supplied name is a correct Pascal unit name

FilenameIsPascalUnit - checks that the supplied name is a correct Pascal unit name

Looks at the file extension to see if it matches one of the standard Pascal extensions (currently .p, .pp, .pas)

Returns True if the supplied name is a correct Pascal Unit filename
The name of the file for checking
Appends the path delimeter to the path.
AppendPathDelim checks if the last character in the path is the path delimeter. If it isn't the path delimeter, it is added, otherwise the unmodified path is returned.
Returns a new path name including delimiter, if it was not already there, otherwise returns original pathname
Path - name for checking
Removes trailing path delimeter
ChompPathDelim checks if the last character in the path is the path delimeter. If it is the path delimeter, it is removed, otherwise the unmodified path is returned.
Returns new path name with delimiter removed if it was there, otherwise returns original path name
Path name for checking
TrimFilename
- trim double path delimiters, heading and trailing spaces and special dirs . and ..
Returns the original file name if no trimming was needed, otherwise returns the trimmed file name
The name of the file for trimming
CleanAndExpandFilename
- trims irrelevant characters such as path delimiters from the name of the file
Returns the original file name without redundant leading or trailing spaces, path delimiters etc
The name of the file for processing
CleanAndExpandDirectory
- trims and cleans

FileName
and appends a directory delimiter to it
Returns the cleaned file name with appended directory delimiter
The name of the file for operation
CreateAbsoluteSearchPath
- concatenates

BaseDirectory
and

SearchPath
to form an absolute path to search for files

CreateAbsoluteSearchPath - concatenates

BaseDirectory and

SearchPath to form an absolute path to search for files

Adds appropriate path delimiters to the BaseDirectory string, then adds the search path, checking that each directory in the path is in fact an absolutely specified directory, then returns the fully formed absolute search path.

If BaseDirectory is empty, functions exits and returns with Result equal to SearchPath; if SearchPath is empty, function exits with empty Result
The absolute path formed by concatenating BaseDirectory and SearchPath
The search path (a relative path)
The base directory from which to form the absolute path
CreateRelativePath
- given an absolute path and a

BaseDirectory,
create a search path relative to the current directory

CreateRelativePath - given an absolute path and a

BaseDirectory, create a search path relative to the current directory

The returned string includes the correct number of dots and double dots to signify relativity to the current directory (eg ../../or ..\..\ etc)

If BaseDirectory is empty, functions exits and returns with Result equal to Filename; if Filename is empty, function exits with empty Result
The file name expressed as path relative to the current directory
The absolute FileName for which a relative path is to be created
BaseDirectory
of the absolute search path
FileIsInPath
- checks that

FileName
refers to a file that exists within the given

Path
Returns True if a file named Filename exists within the given Path
The name of the file for checking
The Path to be searched
FileIsInDirectory
- checks whether a file with

FileName
exists within the given

Directory

FileIsInDirectory - checks whether a file with

FileName exists within the given

Directory

Returns True if the file is in the directory
The name of the file to be checked
The name of the directory to be searched for the file
AllDirectoryEntriesMask
- typically '*' on most systems
File mask representing all files suitable for showing in a file filter.
GetAllFilesMask returns a File Mask suitable for showing in a filter of a Open File Dialog.

windows '*.*' is returned, on other operating systems just '*'.
GetExeExt
- find the correct extension for an executable file
Returns '.exe' in Windows, nothing in other systems
SearchFileInPath
- searches for Filename in the given SearchPath using the supplied BasePath with the specified Delimiter and the options listed in Flags

Searches the whole path unless the sffDontSearchInBasePath flag is present

Returns the first file that matches the supplied criteria

If the file does not exist, an empty string is returned
Returns fully specified file name of the first file that matches the supplied criteria, or empty string if file not found
The name of the file for searching
The BasePath to be used for the search
The path for searching
The directory Delimiter to be used in the search
Flags
specifying how to search: e.g. don't search in base path, case independent search
SearchAllFilesInPath
- searches for all files named Filename in the given SearchPath using the supplied BasePath with the specified Delimiter and the options listed in Flags

Searches the whole path unless the sffDontSearchInBasePath flag is present

Returns all files that match the supplied criteria

Returns fully specified file names of all files that match the supplied criteria, or empty string if file not found
The name of the file for searching
The BasePath to be used for the search
The path for searching
The directory Delimiter to be used in the search
Flags
specifying how to search: e.g. don't search in base path, case independent search
FindDiskFilename
- finds the file that best fits the supplied filename

FindDiskFilename - finds the file that best fits the supplied filename

Searches for the filename case on disk. The file must exist.

For example: If Filename='file' and there is only a 'File' then 'File' will be returned.

Returns the best fitting filename from the disk (taking case into consideration)
The name of the file for checking
FindDiskFileCaseInsensitive
- searches for the given

FileName
in a case insensitive manner
If it exists, returns the file name with path information otherwise returns an empty string
The name of the file for processing
FindDefaultExecutablePath
- finds the default path to the named Executable file

FindDefaultExecutablePath - finds the default path to the named Executable file

On Windows systems, looks for the '.EXE' extension

In all systems, searches the 'PATH' environment variable to see if the file is in one of the default paths

Returns the filename of the Executable file with path information attached
The name of the Executable file
Class for getting info about found file or directory.
Stops the searching process.
If the current file is directory.
Gets the current file name.
Gets the current file info.
Gets the current file path level relative to base search path.
Gets the current file path.
If the searching is in process.
Class for searching files.
Creates new file searcher object.
Searches for files in specified path with passed options.
Searches for files in specified path. When file is found the OnFileFound event is invoked, for directories OnDirectoryFound event. You can abort searching process by calling Stop method in this events.
Base path for searching files.
Mask which file should match.
If search recursively sub directories.
Is invoked when directory is found.
Is invoked when file is found.
Returns the list of found files in the specified path according to passed options.
List of found files.
Base path for searching files.
Mask which file should match.
If search recursively sub directories.
ReadFileToString
- returns a string with the contents of the named file

Opens the file and reads its contents into a Stream, then reads the stream to construct the Result string

If there is an error in reading the file, an exception is raised and an empty string is returned
The contents of the file as a string, or an empty string if there is an error or the file is empty
The name of the file for processing
CopyFile
- copies Source file to Destination file, optionally preserving the time stamp of the original file
An exception is raised if the Copy process does not complete successfully or correctly
Returns True if successful, False if there was an error
The source filename for the Copy
The destination filename for the Copy
If True, the time stamp of the original file is preserved in the copied file
GetTempFilename
- finds a suitable name for a temporary file

GetTempFilename - finds a suitable name for a temporary file

Uses Prefix plus an integer to generate a file with extension '.tmp' in the specified Directory; if it already exists, increments the integer until it finds a name that is not already used
Returns the temporary file name that has been created
The Directory in which the temprary file is to be placed
The Prefix to which an integer will be attached to generate a temporary filename