var ofOpenRead = O_RDONLY $80000000;
Use this flag (in combination with others) to open file for "read" only.
var ofOpenWrite = O_WRONLY $40000000;
Use this flag (in combination with others) to open file for "write" only.
var ofOpenReadWrite = O_RDWR $C0000000;
Use this flag (in combination with others) to open file for "read" and "write".
var ofShareExclusive = $10 $00;
Use this flag (in combination with others) to open file for exclusive use.
var ofShareDenyWrite = $20 $01;
Use this flag (in combination with others) to open file in share mode, when only attempts to open it in other process for "write" will be impossible. I.e., other processes could open this file simultaneously for read only access.
var ofShareDenyRead = 0 $02;
Use this flag (in combination with others) to open file in share mode, when only attempts to open it for "read" in other processes will be disabled. I.e., other processes could open it for "write" only access.
var ofShareDenyNone = $30 $03;
Use this flag (in combination with others) to open file in full sharing mode. I.e. any process will be able open this file using the same share flag.
var ofCreateNew = O_CREAT or O_TRUNC $100;
Default creation disposition. Use this flag for creating new file (usually for write access.
var ofCreateAlways = O_CREAT $200;
Use this flag (in combination with others) to open existing or creating new file. If existing file is opened, it is truncated to size 0.
var ofOpenExisting = 0 $300;
Use this flag (in combination with others) to open existing file only.
var ofOpenAlways = O_CREAT $400;
Use this flag (in combination with others) to open existing or create new (if such file is not yet exists).
var ofTruncateExisting = O_TRUNC $500;
Use this flag (in combination with others) to open existing file and truncate it to size 0.
var ofAttrReadOnly = 0 $10000;
Use this flag to create Read-Only file (?).
var ofAttrHidden = 0 $20000;
Use this flag to create hidden file.
var ofAttrSystem = 0 $40000;
Use this flag to create system file.
var ofAttrTemp = 0 $1000000;
Use this flag to create temp file.
var ofAttrArchive = 0 $200000;
Use this flag to create archive file.
var ofAttrCompressed = 0 $8000000;
Use this flag to create compressed file. Has effect only on NTFS, and only if ofAttrCompressed is not specified also.
var ofAttrOffline = 0 $10000000;
Use this flag to create offline file.
function WFileCreate( const FileName: KOLWideString; OpenFlags: DWord ): THandle;
function FileCreate( const FileName: KOLString; OpenFlags: DWord ): THandle;
Call this function to open existing or create new file. OpenFlags parameter can be a combination of up to three flags (by one from each group:
1st group. Here You decide wish You open file for read, write or read-and-write operations. |
|
---|---|
ofShareExclusive, ofShareDenyWrite, ofShareDenyRead, ofShareDenyNone |
2nd group - sharing. Here You can mark out sharing mode, which is used to open file. |
ofCreateNew, ofCreateAlways, ofOpenExisting, ofOpenAlways, ofTruncateExisting |
3rd group - creation disposition. Here You determine, either to create new or open existing file and if to truncate existing or not. |
function FileClose( Handle: THandle ): Boolean;
Call it to close opened earlier file.
function FileExists( const FileName: KOLString ): Boolean;
Returns True, if given file exists.
Note (by Dod): It is not documented in a help for GetFileAttributes, but it seems that under NT-based Windows systems, FALSE is always returned for files opened for excluseve use like pagefile.sys.
function WFileExists( const FileName: KOLWideString ): Boolean;
Returns True, if given file exists.
Note (by Dod): It is not documented in a help for GetFileAttributes, but it seems that under NT-based Windows systems, FALSE is always returned for files opened for excluseve use like pagefile.sys.
function FileSeek( Handle: THandle; const MoveTo: TStrmMove; MoveMethod: TMoveMethod ): TStrmSize;
Changes current position in file.
function FileRead( Handle: THandle; var Buffer; Count: DWord ): DWord;
Reads bytes from current position in file to buffer. Returns number of read bytes.
function File2Str( Handle: THandle ): AnsiString;
Reads file from current position to the end and returns result as ansi string.
function File2WStr( Handle: THandle ): KOLWideString;
Reads UNICODE file from current position to the end and returns result as unicode string.
function FileWrite( Handle: THandle; const Buffer; Count: DWord ): DWord;
Writes bytes from buffer to file from current position, extending its size if needed.
function FileEOF( Handle: THandle ): Boolean;
Returns True, if EOF is achieved during read operations or last byte is overwritten or append made to extend file during last write operation.
function FileFullPath( const FileName: KOLString ): KOLString;
Returns full path name for given file. Validness of source FileName path is not checked at all.
function FileShortPath( const FileName: KOLString ): KOLString;
Returns short path to the file or directory.
function FileIconSystemIdx( const Path: KOLString ): Integer;
Returns index of the index of the system icon correspondent to the file or directory in system icon image list.
function FileIconSysIdxOffline( const Path: KOLString ): Integer;
The same as FileIconSystemIdx, but an icon is calculated for the file as it were offline (it is possible to get an icon for file even if it is not existing, on base of its extension only).
function DirIconSysIdxOffline( const Path: KOLString ): Integer;
The same as FileIconSysIdxOffline, but for a folder rather then for a file.
procedure LogFileOutput( const filepath, str: KOLString );
Debug function. Use it to append given string to the end of the given file.
function Str2File( Filename: PKOLChar; Str: PAnsiChar ): Boolean;
Save null-terminated string to file directly. If file does not exists, it is created. If it exists, it is overriden. If operation failed, FALSE is returned.
function WStr2File( Filename: PKOLChar; Str: PWideChar ): Boolean;
Save null-terminated wide string to file directly. If file does not exists, it is created. If it exists, it is overriden. If operation failed, FALSE is returned.
function StrSaveToFile( const Filename: KOLString; const Str: AnsiString ): Boolean;
Saves a string to a file without any changes. If file does not exists, it is created. If it exists, it is overriden. If operation failed, FALSE is returned.
function StrLoadFromFile( const Filename: KOLString ): AnsiString;
Reads entire file and returns its content as a string. If operation failed, an empty strinng is returned.
by Sergey Shishmintzev: it is possible to pass Filename = 'CON' to read input from redirected console output.
function WStrSaveToFile( const Filename: KOLString; const Str: KOLWideString ): Boolean;
Saves a string to a file without any changes. If file does not exists, it is created. If it exists, it is overriden. If operation failed, FALSE is returned.
function WStrLoadFromFile( const Filename: KOLString ): KOLWideString;
Reads entire file and returns its content as a string. If operation failed, an empty strinng is returned.
by Sergey Shishmintzev: it is possible to pass Filename = 'CON' to read input from redirected console output.
function Mem2File( Filename: PKOLChar; Mem: Pointer; Len: Integer ): Integer;
Saves memory block to a file (if file exists it is overriden, created new if not exists).
function File2Mem( Filename: PKOLChar; Mem: Pointer; MaxLen: Integer ): Integer;
Loads file content to memory.
procedure FileTime( const Path: KOLString; CreateTime, LastAccessTime, LastModifyTime: PFileTime ); stdcall;
Returns file times without opening it.
function GetUniqueFilename( PathName: KOLString ): KOLString;
If file given by PathName exists, modifies it to create unique filename in target folder and returns it. Modification is performed by incrementing last number in name (if name part of file does not represent a number, such number is generated and concatenated to it). E.g., if file aaa.aaa is already exist, the function checks names aaa1.aaa, aaa2.aaa, ..., aaa10.aaa, etc. For name abc123.ext, names abc124.ext, abc125.ext, etc. will be checked.
function FileTimeCompare( const FT1, FT2: TFileTime ): Integer;
Compares time of file (createing, writing, accessing. Returns -1, 0, 1 if correspondantly FT1<FT2, FT1=FT2, FT1>FT2.
function DirectoryExists( const Name: KOLString ): Boolean;
Returns True if given directory (folder) exists.
function DiskPresent( const DrivePath: KOLString ): Boolean;
Returns TRUE if the disk is present
function WDirectoryExists( const Name: KOLWideString ): Boolean;
function CheckDirectoryContent( const Name: KOLString; SubDirsOnly: Boolean; const Mask: KOLString ): Boolean;
Returns TRUE if directory does not contain files (or directories only) satisfying given mask.
function DirectoryEmpty( const Name: KOLString ): Boolean;
Returns True if given directory is not exists or empty.
function DirectoryHasSubdirs( const Path: KOLString ): Boolean;
Returns TRUE if given directory exists and has subdirectories.
function DirectorySize( const Path: KOLString ): I64;
Returns directory size in bytes as large 64 bit integer.
function GetStartDir: KOLString;
Returns path to directory where executable is located (regardless of current directory).
Returns the path to the exe-file (in case of dll hook, this is exe-file of the process in which context dll hook function is called).
function ModulePath: KOLString;
Returns the path to the module (exe, dll) itself.
function ExcludeTrailingChar( const S: KOLString; C: KOLChar ): KOLString;
If S is finished with character C, it is excluded.
function IncludeTrailingChar( const S: KOLString; C: KOLChar ): KOLString;
If S is not finished with character C, it is added.
function IncludeTrailingPathDelimiter( const S: KOLString ): KOLString;
by Edward Aretino. Adds '\' to the end if it is not present.
function ExcludeTrailingPathDelimiter( const S: KOLString ): KOLString;
by Edward Aretino. Removes '\' at the end if it is present.
function ExtractFileDrive( const Path: KOLString ): KOLString;
Returns only drive part from exact path to a file or a directory. For network paths, returns a computer name together with a following name of shared directory (like '\\compname\shared\' ).
function ExtractFilePath( const Path: KOLString ): KOLString;
Returns only path part from exact path to file.
function WExtractFilePath( const Path: KOLWideString ): KOLWideString;
Returns only path part from exact path to file.
function IsNetworkPath( const Path: KOLString ): Boolean;
Returns TRUE, if Path is starting from '\\'.
function ExtractFileName( const Path: KOLString ): KOLString;
Extracts file name from exact path to file.
function ExtractFileNameWOext( const Path: KOLString ): KOLString;
Extracts file name from path to file or from filename.
function ExtractFileExt( const Path: KOLString ): KOLString;
Extracts extention from file name (returns it with dot '.' first)
function ReplaceExt( const Path, NewExt: KOLString ): KOLString;
Returns Path to a file with extension replaced to a new extension. Pass a new extension started with '.', e.g. '.txt'.
function ForceDirectories( Dir: KOLString ): Boolean;
by Edward Aretino. Creates given directory if not present. All needed subdirectories are created if necessary.
function CreateDir( const Dir: KOLString ): Boolean;
by Edward Aretino. Creates given directory.
function ChangeFileExt( FileName: KOLString; const Extension: KOLString ): KOLString;
by Edward Aretino. Changes file extention.
function ReplaceFileExt( const Path, NewExt: KOLString ): KOLString;
Returns a path with extension replaced to a given one.
function ExtractShortPathName( const Path: KOLString ): KOLString;
function FilePathShortened( const Path: KOLString; MaxLen: Integer ): KOLString;
Returns shortened file path to fit MaxLen characters.
function FilePathShortenPixels( const Path: KOLString; DC: HDC; MaxPixels: Integer ): KOLString;
Returns shortened file path to fit MaxPixels for a given DC. If you pass Canvas.Handle of any control or bitmap object, ensure that font is valid for it (or call TCanvas.RequiredState( FontValid ) method before. If DC passed = 0, call is equivalent to call FilePathShortened, and MaxPixels means in such case maximum number of characters.
function MinimizeName( const Path: KOLString; DC: HDC; MaxPixels: Integer ): KOLString;
Exactly the same as MinimizeName in FileCtrl.pas (VCL).
function GetSystemDir: KOLString;
Returns path to windows system directory.
function GetWindowsDir: KOLString;
Returns path to Windows directory.
function GetWorkDir: KOLString;
Returns path to application's working directory.
function GetTempDir: KOLString;
Returns path to default temp folder (directory to place temporary files).
function CreateTempFile( const DirPath, Prefix: KOLString ): KOLString;
Returns path to just created temporary file.
function GetFileListStr( FPath, FMask: KOLString ): KOLString;
List of files in string, separating each path from others with a character stored in FileOpSeparator variables (#13 by default). E.g.: 'c:\tmp\unit1.dcu'#13'c:\tmp\unit1.~pa' (for use with DeleteFile2Recycle())
function DeleteFiles( const DirPath: KOLString ): Boolean;
Deletes files by file mask (given with wildcards '*' and '?').
function DoFileOp( const FromList, ToList: KOLString; FileOp: UINT; Flags: Word; Title: PKOLChar ): Boolean;
By Unknown Mystic. FileOp can be: FO_MOVE, FO_COPY, FO_DELETE, FO_RENAME. Flags can be a combination of values: FOF_MULTIDESTFILES, FOF_CONFIRMMOUSE, FOF_SILENT, FOF_RENAMEONCOLLISION, FOF_NOCONFIRMATION, FOF_WANTMAPPINGHANDLE, FOF_ALLOWUNDO, FOF_FILESONLY, FOF_SIMPLEPROGRESS, FOF_NOCONFIRMMKDIR, FOF_NOERRORUI. Title used only with FOF_SIMPLEPROGRESS.
function DeleteFile2Recycle( const Filename: KOLString ): Boolean;
Deletes file to recycle bin. This operation can be very slow, when called for a single file. To delete group of files at once (fast), pass a list of paths to files to be deleted, separating each path from others with a character stored in FileOpSeparator variable (by default #13, but in case when OLD_COMPAT symbol added - ';'). E.g.: 'unit1.dcu'#13'unit1.~pa'
FALSE is returned only in case when at least one file was not deleted successfully.
Note, that files are deleted not to recycle bin, if wildcards are used or not fully qualified paths to files.
function CopyMoveFiles( const FromList, ToList: KOLString; Move: Boolean ): Boolean;