CopyFile

From Lazarus wiki
Revision as of 07:11, 22 July 2014 by BigChimp (talk | contribs) (mention lclbase)
Jump to navigationJump to search

Template:Translate

Unit: Lazarus fileutil (UTF-8 replacements for FPC RTL code and additional file/directory handling)

// flags for copy
type
 TCopyFileFlag = (
   cffOverwriteFile,
   cffCreateDestDirectory,
   cffPreserveTime
   );
 TCopyFileFlags = set of TCopyFileFlag;

function CopyFile(const SrcFilename, DestFilename: string): boolean;
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean;
function CopyFile(const SrcFilename, DestFilename: string; Flags: TCopyFileFlags=[cffOverwriteFile]): boolean;

copyfile copies a source file to a destination file location. Optionally it preserves the file's timestamp.

Example:

uses 
...
fileutil
...
CopyFile('c:\autoexec.bat','c:\windows\temp\autoexec.bat.backup');

Function result Returns True if successful, False if there was an error

Light bulb  Note: You can also use this function in command line programs by adding a project requirement for LCLBase, which will not pull in the entire LCL