File Copy / Backup Functions

Copy / Backup Functions

FileCopy Copies file(s) normally or in backup mode
FileCCLose Closes a file after backup mode
FileCCont Copies sections of a file in backup mode
FileCDaTi Determines which date the target file contains with a FileCopy()
FileCOpen Tests to see if the file is still open in the backup mode

FileCCont

FileCCont

Copies sections of a file in backup mode

Syntax

      FileCCont(<cFile>) --> <nCopyByte>

Argument

<cFile> : The file name for the target file.

Returns

<nCopyByte> : number of bytes copied

Description

FILE COPY CONTINUE

Use this function primarily after a FileCopy(). As much as possible of the remaining data is written to a new disk. If the remaining data still does not fit on the designated target disk, call this function repeatedly until it writes all the remaining data. Each time you call FileCCont(), a new name can be designated for the target file. These files are then numbered consecutively (see Examples).

Notes

. If a copy procedure on multiple disks terminates for any reason, call FileCClose().

. Use SETFCREATE() to designate an attribute to form a new file.

. The function acknowledges the CSETSAFETY() implementation, as does FileCopy()

Example

      . Show a back up with FileCopy().  After terminating, close the source
      file:

      FileCopy(cSource, cTarget, .T.)   // Back up mode
      DO NEXTDISK                       // When terminated  Terminated = .T.
      DO WHILE FILECOPEN() .AND. .NOT. Terminated
         FileCCont(cTarget)             // Next disk, new name
         DO NEXTDISK                    // Request for disk exchange
      ENDDO
      IF Terminated
         FileCClose()                   // Close source file!
      ENDIF

Seealso

FileCopy(), FileCOpen(), FileCClose(), FileCDaTi()

FileCClose

FileCClose

Closes a file after backup mode

Syntax

      FileCClose() --> <lClosed>

Returns

<lClosed> : .T., when the the file that was opened with FileCopy() is successfully closed.

Description

FILE COPY CLOSE

After you copy on multiple disks, this function should be routinely called. This is to prevent the source file, previously designed with FileCopy(), from remaining open. For example, this may occur if you terminate the copy procedure.

Note

. Regardless of the share mode, all other users are not allowed access. This situation stays this way without needing a file handle.

Example

      Show a back up with FileCopy().  After terminating, close the source
      file:

      FileCopy(cSource, cTarget, .T.)      // Back up mode
      DO NEXTDISK                          // When terminated Terminated = .T.
      DO WHILE FileCOpen() .AND. .NOT. Terminated
         FileCCont(cTarget)                // Next disk, new name
         DO NEXTDISK                       // Request for disk exchange
      ENDDO
      IF Terminated
         FileCClose()                      // Close source file!
      ENDIF

Seealso

FileCopy(), FileCCont(), FileCOpen(), FileCDaTi()

CT_FILECOPEN

 FILECOPEN()
 Tests to see if the file is still open in the backup mode

 Syntax

     FILECOPEN() --> lOpenFile

 Returns

     FILECOPEN() returns .T. when all data is not copied during a  FILECOPY()
     or FILECCONT().

 Description

     FILE COPY OPEN
     FILECOPEN() determines whether all data is copied.  This concerns the
     source file, which is specified when the FILECOPY() function is called.
     FILECOPEN() returns .T. until all the data in the source file is read,
     whether by FILECOPY or the follow-on function FILECCONT()

 Note

     .  If you must abort the copy process, and FILECOPEN() continues
        to returns .T., use FILECCLOSE().

 Examples

     Show a back up with 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
     FILECCLOSE                        // For safety


See Also: FILECOPY() FILECCONT() FILECCLOSE()

 

Tools — Disk Utilities

Introduction Disk Utilities
DELETEFILE() Deletes an error-tolerant file
DIRCHANGE()  Changes the current directory
DIRMAKE()    Creates a directory
DIRNAME()    Determines the name of the current directory
DIRREMOVE()  Removes a directory
DISKCHANGE() Changes the current disk drive
DISKCHECK()  Creates a checksum for a disk
DISKFORMAT() Formats disks, controlled through a UDF
DISKFREE()   Determines the space available on a floppy or hard disk
DISKNAME()   Determines the drive designator for the current drive
DISKREADY()  Tests to see if a disk drive is ready
DISKREADYW() Queries whether you can write to a drive
DISKSPEED()  Determines a comparison value for the drive speed
DISKSTAT()   Determines the status of a drive.
DISKTOTAL()  Determines the total capacity of a floppy or hard disk
DISKTYPE()   Determines the type of data carrier
DRIVETYPE()  Determines the drive type
FILEAPPEND() Appends data to a file
FILEATTR()   Determines a file's attributes
FILECCLOSE() Closes a file after backup mode
FILECCONT()  Copies sections of a file in backup mode
FILECDATI()  Determines which date the target file contains with FILECOPY()
FILECHECK()  Calculates/computes/determines a checksum for a file
FILECOPEN()  Tests to see if the file is still open in the backup mode
FILECOPY()   Copies files normally or in backup mode
FILEDATE()   Determines the file date
FILEDELETE() Deletes file(s) by name and attribute
FILEMOVE()   Moves files to another directory
FILESEEK()   Searches for files by name and attribute
FILESIZE()   Determines the size of a file
FILESTR()    Reads a portion of a file into a string
FILETIME()   Determines a file's time
FILEVALID()  Tests whether a string has a valid file name
FLOPPYTYPE() Determines the exact type of floppy drive
GETSHARE()   Determines the file open (share) mode
NUMDISKF()   Determines the number of installed disk drives
NUMDISKH()   Determines the number of hard disks
NUMDISKL()   Determines the number of available logical drives
RENAMEFILE() Fault tolerant renaming of a file.
RESTFSEEK()  Restores the FILESEEK environment
SAVEFSEEK()  Saves the current FILESEEK environment
SETFATTR()   Sets a file's attributes
SETFCREATE() Default attribute for creating with CA-Clipper Tools functions
SETFDATI()   Sets the date and time of a file
SETSHARE()   Sets default opening mode for CA-Clipper Tools file functions
STRFILE()    Writes a string to a file
TEMPFILE()   Creates a file for temporary use
TRUENAME()   Standardizes the path designation
VOLSERIAL()  Determines the DOS disk serial number
VOLUME()     Establishes a volume label for a floppy or hard disk

FileCopy

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()