Skip to content

CopyFile (copy a file)

ts
function CopyFile(what: string, toWhere: string): boolean;

Copies the file specified by what to the toWhere destination directory in the local file system. Returns true if the copy is successful, or false if it fails.

ParameterTypeRequirementExplanation
whatstringrequiredPath to a valid, existing file in the local file system
toWherestringrequiredPath to a valid, existing directory in the local file system where the file will be copied
Return valueExplanation
trueThe file was successfully copied to the destination folder
falseThe copy operation failed; the file was not copied

NOTE

This function does not overwrite existing files in the destination directory. If a file with the same name already exists in toWhere, the operation will fail and return false.

Example

ts
var result = CopyFile('/home/user/data.txt', '/home/user/backup');
if (result) {
  Log('File copied successfully.');
} else {
  Log('File copy failed.');
}