uses Sysutils
Directories
====== Create a Directory :CreateDir('c:\path'); Remove a Directory : RemoveDir('c:\path') or RmDir('c:\path') Change a Directory : ChDir('c:\path') Current Directory : GetCurrentDir Check if a Directory exists : if DirectoryExists('c:\path') then ...
Files
=== Rename a File : RenameFile('file1.txt', 'file2.xyz') Delete a File : DeleteFile('c:\text.txt') Move a File : MoveFile('C:\file1.txt','D:\file1.txt'); Copy a File :* CopyFile(Pchar(File1),PChar(File2),bFailIfExists) Change a File's Extension : ChangeFileExt('test.txt', 'xls') Check if a File exists : if FileExists('c:\filename.tst') then ...
The CopyFile function copies an existing file to a new file.
CopyFile(
lpExistingFileName : PChar, // name of an existing file
lpNewFileName : PChar, // name of new file
bFailIfExists : Boolean); // operation if file exists
bFailIfExists:
Specifies how this operation is to proceed if a file of the same name as
that specified by lpNewFileName already exists.
If this parameter is TRUE and the new file already exists, the function fails.
If this parameter is FALSE and the new file already exists,
the function overwrites the existing file and succeeds.
}
var fileSource, fileDest: string; begin fileSource := 'C:\SourceFile.txt';
fileDest := 'G:\DestFile.txt';
CopyFile(PChar(fileSource), PChar(fileDest), False); end;