CitectVBA Programming Reference > CitectVBA Function Reference > File I/O Functions > FileCopy

FileCopy

Copies a file from Src to Dest.

The required source file (Src) and destination file (Dest) arguments must be valid string expressions representing valid file names. Src is the file name of the file to copy from. Dest is the file name to be copied to. Both Src and Dest arguments may contain a DOS path structure including directory or folder names, and a drive letter.

If the Dest file does not exist, it will be created by the FileCopy statement. If the Dest file already exists, it will be overwritten.

The FileCopy statement does not work on a currently open file. Both the Src and Dest files must be closed before using the FileCopy statement. To close an open file, use the Close statement.

Note: The file system keeps track of the current drive, and the current directory of every drive. Use the CurDir statement to determine the current directory. The current drive letter can be extracted from the Left character returned in the CurDir statement.

Syntax

FileCopySrc, Dest

Src:

A string or expression that can represent a valid DOS file structure FileName. Src is case insensitive. This may include a relative or static Path including directory or folder structure and drive letter. To specify multiple files, the FileName may consist of multiple-character ( * ) and single-character ( ? ) wildcards in the file name.

Dest:

A string or expression that can represent a valid DOS file structure FileName. Dest is case insensitive. This may include a relative or static Path including directory or folder structure and drive letter. To specify multiple files, the FileName may consist of multiple-character ( * ) and single-character ( ? ) wildcards in the file name.

Related Functions

Close | FreeFile | Kill | Name | Open

Example

Dim SourceFile as String, DestinationFile as String
SourceFile = "SRCFILE.Dat" ' Define source file name.
DestinationFile = "DESTFILE.Dat" ' Define target file name.
FileCopy SourceFile, DestinationFile ' Copy source to target.