FileCopy

Copies files.

Syntax:

FileCopy (source-list, destination, warning)

Parameters:

(s) source-list a string containing one or more filenames, which may be wildcarded.

(s) destination target path and/or file name/wildcard.

(i) warning @TRUE if you want a warning before overwriting existing files; @FALSE if no warning desired.

Returns:

(i) @TRUE if all files were copied successfully (see below).

 

Source-list and destination may contain * and ? wildcards.

Note: If warning parameter is set to @TRUE , then the return value will be @TRUE, even if it was modified by the user dialog.

If a FileCopy fails, it is often for the following reason:

The target file is in use and cannot be overwritten. In this case, check the status of the file with the FileExist function. If FileExist returns a 2, the file is in-use.

Use this function to copy an individual file, a group of files using wildcards, or several groups of files by separating the names with a delimiter.

You can also copy files to any COM or LPT device, but do not place a colon after the name of the device.

Windows Vista/2008 and newer: This function may require an Administrator level account if dealing with files located in a protected directories: 'Program Files' and 'Windows'.

This function supports extended-length path names.

Examples:

;;;Example 1
temp=Environment("TEMP")
DirChange(DirWindows(0))
FileCopy("*.ini", temp, @TRUE)
Message("FileCopy","Windows ini files backed up to %temp%")

;;;Example 2
;Copies all files in "MyDir" to a "Temp" directory
;and checks that the source files are
;NOT open in read deny mode
filelist=FileItemize("C:\MyDir\*.*")
count=ItemCount(filelist,@TAB)
DirChange("C:\MyDir\")
For xx = 1 To count
   file=ItemExtract(xx,filelist,@TAB)
   If FileExist(file)==2
      Message("Copy failed","%file% is in read-deny mode.")
   Else
      FileCopy(file, "C:\Temp\*.*", @FALSE)
   EndIf
Next
Message("Files copied","Sucessful")
Exit

;;;Example 3
;Print file to LPT1 example
;This example is designed to force a file
;to print on most laser printers
;file name to print
myfile="C:\WINDOWS\desktop\myfile.txt"
;Create a file with a formfeed to send to printer
;(Used to actually force file to print)
home_dir=DirHome()
formfeed_file="%home_dir%print.txt"
file_handle=FileOpen(formfeed_file,"WRITE")
;inserts a form feed into the file
FileWrite(file_handle, Num2Char(12)) FileClose(file_handle)
;execute file copys to LPT1
FileCopy(myfile,"LPT1",@FALSE)
FileCopy(formfeed_file,"LPT1",@FALSE)
;cleanup
FileDelete(formfeed_file)
Message("Print Job", "Complete")
Exit

 

See Also:

IntControl 39, FileAppend, FileDelete, FileExist, FileLocate, FileMove, FileRename