Sign in Join
FPDoc Onlineexperiment

FileUtil unit

Miscellaneous routines, types, and classes for manipulating files, file names, and paths.

fileutils.pas contains routines, types, and classes used to maintain compatibility with the FileUtil unit in Delphi. File routines that deal with UTF-8 file names are located in the LazFileUtils unit.

File name handling in the unit is platform- or OS-specific. For the Windows, Darwin (macOS), and Amiga platforms, file names are NOT case sensitive. In addition, under Darwin, the NotLiteralFilenames define is enabled. This indicates that file names cannot be compared using the = string operator.

This unit contains basic functions similar to those in the RTL, but use UTF-8 instead of the default system encoding. Please note that AnsiToUTF8 and UTF8ToAnsi need a widestring manager under Linux, BSD, and macOS. Normally these operating systems use UTF-8 as the system encoding so the WideStringManager is not needed.

fileutil.pas is part of the LazUtils package.

Classes and records

TFileIteratorclassImplements an iterator for file and directory names on the local file system.
TFileSearcherclassImplements an iterator used to search for files or directories.
TListDirectoriesSearcherclassStores directory names matching a given search criteria in a TStrings class instance.
TListFileSearcherclassStores file names matching a search criteria in a TStrings class instance.

Procedures and functions

CompareFilenamesfunctionCompares two file names to see whether they are equal.
ComparePhysicalFilenamesfunctionCompares file names after resolving symbolic links.
CopyDirTreefunctionCopies all file system entries in a source directory to the destination directory using the specified options.
CopyFilefunctionCopies the source file to the destination file using the specified options.
DeleteDirectoryfunctionDeletes the specified directory (or only its contents when OnlyChildren is True).
ExpandUNCFileNameUTF8functionExpands the specified UTF-8-encoded UNC file name to an absolute UNC file name.
ExtractShortPathNameUTF8functionGets a short path name using the 8.3 notation from the UTF-8-encoded value.
FileIsInDirectoryfunctionChecks whether the specified file name shares the path specified in Directory.
FileIsInPathfunctionChecks whether the specified file name shares the path specified in Path.
FilenameHasPascalExtfunctionIndicates whether the specified file name uses a recognized Pascal file extension.
FileSizefunctionGets the size for the specified file name.
FindAllDirectoriesfunctionStores directory names matching the search criteria in a TStringList class instance.
FindAllFilesfunctionReturns the list of files in the specified path matching the search criteria.
FindDefaultExecutablePathfunctionFinds the default path to the named Executable file.
FindDiskFileCaseInsensitivefunctionFindDiskFileCaseInsensitive - searches for the given FileName in a case insensitive manner.
FindDiskFilenamefunctionFinds the file name that most closely matches the specified file name.
GetAllFilesMaskfunctionGets the file mask representing all files in a file filter.
GetExeExtfunctionReturns the file extension (including the starting .) for an executable file on the platform.
ProgramDirectoryfunctionGets the directory where the current program is located.
ProgramDirectoryWithBundlefunctionGets the directory for the current executable without the macOS bundle post-fix.
ReadFileToBytesfunctionReturns a TBytes value with the contents of the specified file.
ReadFileToStringfunctionReturns a string with the contents of the specified file.
SearchAllFilesInPathfunctionSearchAllFilesInPath - searches for all files named Filename in the given SearchPath using the supplied BasePath with the specified Delimiter and the options listed in Flags.
SearchFileInPathfunctionSearches for a file name in a given path using the specified base path and options.

Types

TCopyFileFlagenumerationContains flags used to control actions performed in CopyFile or CopyDirTree.
TCopyFileFlagssetSet type used to store TCopyFileFlag enumeration values.
TDirectoryEnterEventprocedure typeSpecifies an event handler signalled when a new directory is processed with the specified iterator.
TDirectoryFoundEventprocedure typeSpecifies an event handler signalled when a directory is found for the specified iterator.
TFileFoundEventprocedure typeSpecifies an event handler signalled when a file name is found for the specified iterator.
TQueryDirectoryFoundEventprocedure typeSpecifies an event handler signalled when a directory name matching a search criteria is found in TFileSearcher.
TQueryFileFoundEventprocedure typeSpecifies an event handler signalled when a file name matching a search criteria is found in TFileSearcher.
TSearchFileInPathFlagenumerationFlags used to control options used when searching for file(s) in a given path.
TSearchFileInPathFlagssetSet type used to store values from the TSearchFileInPathFlag enumeration.

Constants

AllDirectoryEntriesMaskconstantFile mask used to match all directories entries on the local file system.
FilenamesCaseSensitiveconstantWhen True, uppercase and lowercase file names are equivalent.
FilenamesLiteralconstantWhen True, file names can be compared using the = string operator.
PascalFileExtconstantFile extensions used for Pascal source code files.
PascalSourceExtconstantFile extensions considered to be a Pascal source, project or package file.
sffFindProgramInPathconstantSearch flags used to find a program file in a path on the current platform.
UTF8FileHeaderconstantByte Order Mark (BOM) used at the beginning of UTF-8-encoded files.

Uses

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.