File Management

File Management Function

DeleteFile Deletes an error-tolerant file
ExeName Full File Name of Executable ( Application )
File Tests for the existence of file(s)
FileMove Moves file(s) to another directory
FileDelete Deletes file(s) by name and attribute
FileSeek Searches for files by name and attribute
HB_FNameExists Detect File / Folder existence
HB_ProgName Returns name and directory of the current Harbour program
HB_FileExists Tests for the existence of a file
HB_FileMatch Makes a file comparison with mask
HB_FTempCreate Creates and opens a temporary file
HB_FTempCreateEx Creates and opens a temporary file with extension
RenameFile Fault tolerant renaming of a file
TempFile Creates a file for temporary use

HB_FTempCreateEx

HB_FTempCreateEx

Creates and opens a temporary file.

Syntax

HB_FTempCreateEx( @<cFileName,;
                    <cTempDir>,;
                    <cPrefix>,;
                    <cFileExtension> --> <nFileHandle>

Arguments

 @<cFileName> :must be passed by reference. It receives the file name of the created temporary  file as a character string.

<cTempDir> : A character string specifying the directory where to create the temporary file. It defaults to the operating       system variable SET TEMP or SET TMP. Operating system variables can be queried with function HB_GetEnv().

<cPrefix> : A character string of three characters specifying the prefix to use for the name of the temporary file. It defaults  to the string “hb”.

<nFileExtension> : A character value specifying extension of the temporary file.

Returns

<nFileHandle> : a numeric value > 0 when the temporary file is successfully created. This is the file handle of the created temporary file.

Description

Function HB_FTempCreateEx() creates a temporary file and opens it. The return value is the file handle of the temporary file. It can be used with low level file functions, such as FWrite() to store data in the file. Temporary files are often required in an application.

HB_FTempCreateEx() guarantees that the file name of the newly created file is unique, so that no existing file will be overwritten. To obtain the file name of the temporary file, parameter <cFileName> must be passed by reference. It can then later be passed to function FErase() in order to remove the temporary file from disk.

HB_FTempCreateEx() is similar to HB_FTempCreate(), but allows to control the extension. Note, that the ordering of parameters had slightly changed compared to hb_fsCreateTemp().

Example

      PROC TestHBFTempEx()

         LOCAL nFileHandle
         LOCAL cFileName

         nFileHandle := HB_FTempCreateEx( @cFileName,;   // File Name
                                          ,;             // <cTempDir>
                                          ,;             // <cPrefix>
                                          '.tmp' )       // file extension

         IF nFileHandle > 0
            ? 'Temp file builded with name :', cFileName
            WAIT
            FClose( nFileHandle )
            FErase( cFileName )
         ELSE
            ALERT( "Couldn't build temp file"  )
         ENDI

      RETU // TestHBFTempEx()

Seealso

TempFile(), HB_FTempCreate(), FCreate(), FErase(), FWrite(), HB_GetEnv()

HB_FTempCreate

HB_FTempCreate

Creates and opens a temporary file.

Syntax

      HB_FTempCreate( [<cTempDir>] , ;
                         [<cPrefix>]  , ;
                         [<nFileAttr>], ;
                         [@<cFileName>]  ) --> <nFileHandle>

Arguments

<cTempDir> : An optional character string specifying the directory where to create the temporary file. It defaults to the operating system variable SET TEMP or SET TMP. Operating system variables can be queried with function HB_GetEnv().

<cPrefix> : An optional character string of three characters specifying the prefix to use for the name of the temporary file. It defaults to the string “hb”.

<nFileAttr> : An optional numeric value defining how to create and open the temporary file. See function FCreate() for a description of <nFileAttr>.

@<cFileName> : If specified, <cFileName> must be passed by reference. It receives the file name of the created temporary file as a character string.

Returns

<nFileHandle> : a numeric value > 0 when the temporary file is successfully created. This is the file handle of the created temporary file.

Description

Function HB_FTempCreate() creates a temporary file and opens it. The return value is the file handle of the temporary file. It can be used with low level file functions, such as FWrite() to store data in the file.

Temporary files are often required in an application. HB_FTempCreate() guarantees that the file name of the newly created file is unique, so that no existing file will be overwritten. To obtain the file name of the temporary file, parameter <cFileName> must be passed by reference. It can then later be passed to function FErase() in order to remove the temporary file from disk.

Example

      PROC TestHBFTemp()

         LOCAL nFileHandle
         LOCAL cFileName

         nFileHandle := HB_FTempCreate( ,;   // <cTempDir>
                                        ,;   // <cPrefix>
                                        ,;   // <nFileAttr>
                                        , @cFileName )

         IF nFileHandle > 0
            ? 'Temp file builded with name :', cFileName
            WAIT
            FClose( nFileHandle )
            FErase( cFileName )
         ELSE
            ALERT( "Couldn't build temp file"  )
         ENDI

      RETU // TestHBFTemp()

Seealso

TempFile(), HB_FTempCreateEx(), FCreate(), FErase(), FWrite(), HB_GetEnv()

CT_TEMPFILE

 TEMPFILE()
 Creates a file for temporary use

 Syntax

     TEMPFILE([<cDirectory>], [<cExtension>], [<nFileAttr>])
         --> cFileName

 Arguments

     <cDirectory>  Designates the drive and directory where the temporary
     file is to be created.  The default is the current drive/directory.

     <cExtension>  Designates the file extension for the file.  The
     default is no extension.

     <nFileAttr> Designates a file attribute for the file.  The default
     is the SETFCREATE() setting.

 Returns

     Returns the name of the temporary file.  If no file is created, the
     function returns a null string.

 Description

     If you only need a file for a short time and want to avoid conflicts
     with existing files, use TEMPFILE() to create a file with a unique name.
     Names created by TEMPFILE() use the system date and system time.  You
     can hide the file, if you specify an attribute.  Attributes are coded as
     follows:

     Table 7-24:  File Attribute Coding
     ------------------------------------------------------------------------
     Value   Symb. constants     Definition
     ------------------------------------------------------------------------
     0       FA_NORMAL
     1       FA_READONLY         READ ONLY
     2       FA_HIDDEN           HIDDEN (Hidden files)
     4       FA_SYSTEM           SYSTEM (System files)
     32      FA_ARCHIVE          ARCHIVE (Changed since last backup)
     ------------------------------------------------------------------------

 Notes

     .  The temporary file name is always 8 characters long and
        consists exclusively of numbers with a period, if no extension has
        been specified.  The file is created with a length of 0 bytes.

     .  A designated file attribute has precedence over a setting
        created with SETFCREATE().

 Examples

     .  Create a temporary file in the current drive and directory:

        cTempFile := TEMPFILE()

     .  Create a temporary file in the root directory of the E: drive:

        cTempFile := TEMPFILE("E:\")

     .  Create a temporary file with a .TMP extension and a HIDDEN
        attribute in the root directory of the A: drive:

        cTempFile := TEMPFILE("A:\", "TMP", 2)

See Also: SETFATTR() SETFCREATE()

 

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