Skip to content

CopyFile

See Also: File_Exist, EraseFile, File I/O Commands, Copy_DB

Purpose

Copies one or more disk files.

Syntax

CopyFile {source-file(s)} to {destination}

Where

  • {source-file(s)}: The specification of a file or set of files (including wildcard characters), optionally including a path.

  • {destination}: The specification of a file, set of files, folder, or drive to copy {source-file(s)} to, optionally including a path.

What It Does

CopyFile copies the file(s) identified by {source-file(s)} to the file, folder, or drive identified by {destination}, creating any destination files that do not already exist and overwriting any that do. CopyFile will use the current working folder unless a path is provided as part of {source-file(s)} and/or {destination}. You may use any valid Windows file specification (including wildcard characters) for {source-file(s)}.

Examples

Example 1

This sample copies the file "foo.txt" in the current working folder to a file named "foo2.txt" in the same folder:

CopyFile "foo.txt" to "foo2.txt"

Example 2

This sample copies all files with the file name "foo" and any file extension to the folder "C:\MyFoo":

CopyFile "foo.*" to "C:\MyFoo"

Example 3

This sample copies the file "foo.txt" to drive "F:":

CopyFile "foo.txt" to "F:"

Example 4

This sample copies all files with the file name "vendor" and any file extension to a backup folder:

Procedure BackupVendorData
    String sDataFolder
    // replace {Revision} with DataFlex version, e.g. "14.1"
    Move "C:\DataFlex {Revision} Examples\Order Entry\Data" to sDataFolder
    Set_Directory sDataFolder
    Make_Directory "Backup"
    // Copy Vendor table to backup folder
    CopyFile "Vendor.*" to "Backup"
End_Procedure

Send BackupVendorData

Notes

  • If a CopyFile command is executed on a non-existent source file(s), no error will be triggered. Use the File_Exist command to determine whether a file exists before copying the file(s).

  • If a CopyFile command is executed on source file(s) that already exist in the destination location, no error, warning, or notification will be triggered. Use the File_Exist command to determine whether a file exists in the destination location before copying the file(s).

  • You may use wildcard characters in the source file specification, but not in the destination file specification. When {source-file(s)} contains ambiguous file names, {destination} must not be ambiguous.

  • CopyFile does not copy subfolders. You will have to write code to recurse through subfolders you wish to copy, test for their existence using File_Exist, and create them yourself using Make_Directory.