Previous Topic: File System FunctionsNext Topic: CopyTree - Copy a Directory Tree


CopyFile or Copy Link - Copy an Existing File

Valid on NetWare, Symbian OS, UNIX, Windows and Windows CE

The CopyFile or CopyLink function copies an existing file to a new file.

This file content function has the format:

CopyFile(
	source as String, 
	target as String, 
	overwrite as Boolean) as Boolean
CopyFile(source as String, target as String) as Boolean
source

Specifies the file name of an existing source file.

target

Identifies the name of the new file.

overwrite

Specifies if the function overwrites an existing target. The default, TRUE, overwrites an existing target. FALSE causes the function to fail if the target file already exists.

On successful completion, the function returns TRUE; otherwise, it returns FALSE.

Example: CopyFile function

This example creates a backup directory and copies autoexec.bat to the directory and renames it to autoexec.bat.

HELP_GETFILEATTRIBUTES

If Not(ExistDirectory("c:\backup")) then CreateDirectory("c:\backup")
CopyFile("c:\autoexec.bat", "c:\backup\autoexec.bat") 
RenameFile("c:\backup\autoexec.bat", "c:\backup\autoexec.bak")