FileCopy
Copies files normally or in backup mode
Syntax
FileCopy( <cSourceFile>, ; <cTargetFile>, ; [<lBackup>] ) --> nBytesCopied
Arguments
<cSourceFile> : A character string containing the name of the file to copy to the target file.It must be specified with a file extension. If <cSourceFile> contains no drive and/or directory information, the current directory is used. SET DEFAULT and SET PATH settings are ignored.
<cTargetFile> : A character string holding the name of the target file to create. The file name may include drive and directory and must include an extension. If the file exists already, it is overwritten
<lBackup> : This parameter defaults to .F. (false). When set to .T. (true) the function operates in backup mode. This allows for copying large files to several diskettes.
Return
The funtion returns the number of bytes copied from <cSourceFile> to <cTargetFile>.
Description
The FileCopy() function copies a source file to a target file. The <lBackup> parameter can be used to copy large files to several diskettes. If <lBackup> set to .T. (true), FileCopy() copies the maximum possible number of bytes to the target file (diskette). The function FileCOpen() is then used to check if <cSourceFile> is still open. If this is the case the user can be prompted to insert a new diskette and FileCCont() continues the copying operation.
Example:
. Show a simple copy: ? FileCopy("A:\TEXT.TXT", "C:\TEST.TXT") // Bytes copied . A back up using FileCopy(): nCounter := 1 // "BIG.001" etc. cTargetFile := "BIG" + NTOC(nCounter, 10, 3, "0") FileCopy("BIG.DBF", "A:\" + cTargetFile, .T.) // Back up mode DO WHILE FILECOPEN() DO NEXTDISK // Request disk change nCounter := nCounter + 1 cTargetFile := "BIG" + NTOC(nCounter, 10, 3, "0") FileCCont(cTargetFile) // Next disk - new name ENDDO RETURN PROCEDURE NEXTDISK ? "Please insert new diskette in Drive A:!" WAIT RETURN Another simple File Copy procedure : PROCEDURE Main LOCAL cSourceFile := "C:\Harbour\news.txt" LOCAL cTargetFile := "D:\temp\HRB_News.txt" CLS ? "Copying", cSourceFile, "to", cTargetFile, "..." ? "Copied", FileCopy( cSourceFile, cTargetFile ), "bytes" RETURN
Seealso
COPY, COPY FILE, FileCClose(), FileCCont(), FileCDaTi(), FileCOpen()