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

FileCOpen

FileCOpen

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

Syntax

      FileCOpen() --> <lOpenFile>

Returns

<lOpenFile> : .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

Seealso

FileCopy(), FileCCont(), FileCClose(), FileCDaTi()

FileCDaTi

FileCDaTi

Determines which date the target file contains with a FileCopy().

Syntax

      FileCDaTi([<lNewMode>]) --> <lOldMode>

Argument

<lNewMode> : Designates the new status for FileCDaTi(). When .T. is designated, the target file contains the source file date; when it is .F., the system date. The default is the source file date (.T.).

Returns

If no parameter is designated, FileCDaTi() returns the current setting for FileCDaTi(); otherwise, it returns the previous setting.

Description

FILE COPY DATE TIME

FileCDaTi() Determines whether a source file’s date and time stamp or the system’s date and time stamp, should be used to create or copy a file. Use original or system time for a file copy process.

When you partition to several disks in backup mode, this concerns all target files. Default is .T., where the target file contains the date and time of the source file. If you call FileCDaTi() with the parameter designated .F., then the target file contains the system date and time.

Notes

. Use this function before FileCopy().

. If the target file contains a unique setting such as a pseudo serialization, use the SETFDATI() function.

Examples

      .  Query the FileCDaTi() setting:
         ? FileCDaTi()            // The current setting
      .  The target file is to contain the system date and time:
         ? FileCDaTi(.F.)         // Returns the previous setting

Seealso

FileCopy(),  FileCCont(), FileCClose()

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

CT_FILECCLOSE

 FILECCLOSE()
 Closes a file after backup mode

 Syntax

     FILECCLOSE() --> lClosed

 Returns

     FILECCLOSE() returns .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

See Also: FILECOPY() FILECCONT() FILECOPEN()

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