CopyFile
Copies a file.
Member of namespace
FileIOSyntax
bool CopyFile (string sourcefile, string targetfile, bool overwrite)Parameters
string sourcefilestring targetfile
bool overwrite
Parameters
sourcefile: The name and path of the file to copy. Smart parameters are supported.
targetfile: The target path and file name. Smart parameters are supported.
overwrite: If the target file exists, this parameter determines whether it is overwritten. True overwrites the target file.
Returns
True if the file is successfully copied. Otherwise, False.Level
All levels.Details
The file is copied from one location to the specified location. If a file of the same target name exists in the target directory, the overwrite parameter determines whether that file is overwritten by the new file. The output directory must exist for this action to succeed. You can use action IsDirectoryPresent to create the target directory.If target file ends with a backslash, meaning only the target directory is specified, the same file name from the source string is used as the target file.
Because the target file name can be different from the source file, this action allows the copied file to be renamed in one step. If you want to do a "move" operation, call the DeleteFile action to remove the source file.
Smart parameters are supported in the source and target file name parameters. DOS * and ? wildcards are not supported.
- Example
CopyFile("C:\MyFile.txt", "c:\temp\+@BATCHID+.txt", true)This action copies MyFile.txt to the temp directory and give it a new name of the current batch ID.
CopyFile("@VAR(IMAGEFILE)", "c:\temp\", true)This action copies the file that is specified by the variable IMAGEFILE and copies it to the temp directory.
CopyFile("@VAR(IMAGEFILE)", "@PILOT(BATCHDIR)+\+@ID+.backup", true)Assuming this is called on a page node, this example copies the current image file associated with the current page object to a new file that has a "backup" extension.