xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

FileCopy()

Copies files normally or in backup mode.

Syntax

FileCopy( <cSourceFile>, ;
          <cTargetFile>, ;
         [<lBackup>]     ) --> nBytesCopied

Arguments

<cSourceFile>
This is 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>
This is 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.

Note:  when a large file is copied to multiple diskettes, it can be re-assembled using the FileAppend() function.

Info

See also:CSetSafety(), FileAppend(), FileCClose(), FileCCont()
Category: CT:DiskUtil , File functions , Low level file functions
Source:ct\fcopy.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the two modes of FileCopy()

   PROCEDURE Main
      LOCAL cSourceFile := "LargeFile.txt"
      LOCAL cTargetFile := "NewLargeFile.txt"
      LOCAL nCounter    := 1

      CLS

      ? "Regular copy "
      ?? FileCopy( cSourceFile, cTargetFile ), "bytes"

      ? "Backup copy "
      cTargetFile := "A:\backup.001"

      ?? cTargetFile, FileCopy( cSourceFile, cTargetFile ), "bytes"

      DO WHILE FileCOpen()
         WAIT "Please insert a new diskette in drive A:"

         nCounter ++
         cTargetFile := "A:\backup." + StrZero( nCounter, 3 )
         ? cTargetFile, FileCCont( cTargetFile ), "bytes"
      ENDDO

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe