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_DirScan

HB_DirScan

Scan a directory tree and build a files and folders list

Syntax

      HB_DirScan( , ,  ) --> 

Arguments

: A character string holding the drive, directory and/or file specification to retrieve information for. Default is current directory.

( skeleton > : For filter files to add to the list, (can include wild card characters). Default is ‘*.*’.

: A character string holding file attributes can be specified. Information about files carrying these attributes is retrieved. One or more characters of the table below can be included in . For add directories to the list add ‘D’ to .

Attributes for HB_DirScan() :

         Attribute Meaning
         --------- -------------------------
             A     Archive
             D     Directories
             H     Hidden files
             R     Read-only
             S     System files

Returns

: A two-dimensional array of five columns; holding information about files in the and the that match . An empty array, if no matched file found or an error occured.

Description

The HB_DirScan() function is similair to the Directory(). The first difference is that HB_DirScan() scans recursively all sub- directories in the directory specified with . And second difference is Directory() don’t requires parameter, instead this info included in the .

The result is a two dimensional array . Columns can be accessed using #define constants from the DIRECTRY.CH file.

Constants for the HB_DirScan() array :

         Symbolic Numeric
         Constant Value  Meaning             Data Type
         -------- -----  ------------------- --------------
         F_NAME     1    File name           Character
         F_SIZE     2    File size in bytes  Numeric
         F_DATE     3    File date           Date
         F_TIME     4    File time           Character
         F_ATTR     5    File attributes     Character

Files

Header: Directry.ch

Example

      Assuming this directory tree and files exist :

      C:\
         | temp                     D
         + ---- + Dir1              D
                |      doc1.docx    F
                |      test1.bat    F
                |      test1.txt    F
                + Dir2              D
                |      doc2.docx    F
                |      test2.bat    F
                |      test2.txt    F
                + run.bat           F
                  test.bat          F
                  test.exe          F

      PROC TestDScan()

         LOCAL aFFList := HB_DirScan( "C:\TEMP" )

         LOCAL x1Row

         FOR EACH x1Row IN aFFList
            ? PAD( x1Row[ 1 ], 23 ),;                     // Name
              TRAN( x1Row[ 2 ], '999,999,999,999' ),;     // Size
              x1Row[ 3 ],;                                // Date
              x1Row[ 4 ],;                                // Time
              x1Row[ 5 ]                                  // Attributes
         NEXT x1Row

      RETU // TestDScan()

      Result :

         Dir1\doc1.docx       14,757 26.02.2014 00:04:27 A
         Dir1\test1.bat           54 24.02.2014 00:54:01 A
         Dir1\test1.txt           54 24.02.2014 00:54:01 A
         Dir2\doc2.docx       14,757 26.02.2014 00:04:27 A
         Dir2\test2.bat           54 24.02.2014 00:54:01 A
         Dir2\test2.txt           54 24.02.2014 00:54:01 A
         run.bat               24 27.02.2014 01:12:28 A
         test.bat                 54 24.02.2014 00:54:01 A
         test.exe          1,413,285 27.02.2014 01:10:36 A

      ˜˜˜˜˜˜˜

      HB_DirScan( "C:\TEMP\*.txt" ) <- Incorrect call !

      ˜˜˜˜˜˜˜

      HB_DirScan( "C:\TEMP\", "*.txt" )

      Result :

         Dir1\test1.txt           54 24.02.2014 00:54:01 A
         Dir2\test2.txt           54 24.02.2014 00:54:01 A

Seealso

Directory(), File(), FileSeek(), HB_FileMatch()HB_FileExists(), HB_FNameExists(), HB_DirExists()FileFindXxxx

FileFindXxxx

FileFindXxxx

Searches for files by name and attribute and get file properties

Syntax :

      FileFindFirst( <cFileNameMask>, @<pFFindInfo>[, <nAttr> ] ) -> <lFound>
      FileFindNext(  <pFFindInfo> ) -> <lFound>
      FileFindName(  <pFFindInfo> ) -> <cFileName>
      FileFindAttr(  <pFFindInfo> ) -> <nAttr>
      FileFindSize(  <pFFindInfo> ) -> <nSize>
      FileFindDate(  <pFFindInfo> ) -> <dDate>
      FileFindTime(  <pFFindInfo> ) -> <cTime>

Arguments

<cFileNameMask> : A file name including its path and drive designation. It may contain wildcards.

<pFFindInfo> : A pointer for an internal data structure to hold file(s) info

<nAttr> : The file attribute that corresponds to the ones described in the table on the next page. The default value is 0.

         Coding the File Attribute
         ----------------------------------------------------------------
         Value Symb. constants        Assigned attribute
         ----------- ---------------- -----------------------------------
             0       FA_NORMAL
             1       FA_READONLY      READ ONLY (Read-only)
             2       FA_HIDDEN        HIDDEN (Hidden files)
             4       FA_SYSTEM        SYSTEM (System files)
             8       FA_VOLUME        VOLUME (Name of a floppy/hard disk)
            16       FA_DIRECTORY     DIR (Directory)
            32       FA_ARCHIVE       ARCHIVE (Changes since last backup)
         ----------------------------------------------------------------

Returns

<lFound> : A logical value indicate file existence

<cFileName> : Name of file found by FileFindFirst() or FileFindNext() (without drive/dir)

<nAttr> : A numeric value indicate attribute info of file

<nSize> : A numeric value indicate size of file

<dDate> : A date value indicate date of file

<cTime> : A character value indicate time of file (as “HH:MM:SS”)

Description

FileFindXxxx functions provides a set of info on a set of file.

Calling first FileFindFirst() build an internal data structure ( probably an array like returned by Directory() ). And then calling other FileFindXxxx functions returns individual file info for last file found.

This function set look like FileSeek() function. For more info look at it.

Note

Internal Data Buffer : Every FileFindXxxx() function uses internal data structure <pFFindInfo>. For further using this variable should be passed by reference in FileFindFirst(). May be useful release this buffer by go out of scope or be explicitly release by freeing <pFFindInfo> variable a way like this:

<pFFindInfo> := NIL

Example

      PROC TestFFs()
         LOCAL pFFInfo
         LOCAL nFileNo := 0
         LOCAL lContinue := FileFindFirst( '*.*', @pFFInfo )

         WHIL lContinue
            ? PAD( ++nFileNo, 3),;
              PAD( FileFindName( pFFInfo ), 23 ),;
                   FileFindAttr( pFFInfo ),;
                   FileFindSize( pFFInfo ),;
                   FileFindDate( pFFInfo ),;
                   FileFindTime( pFFInfo )
            lContinue := FileFindNext( pFFInfo )
         END

         RETU // TestFFs()

Seealso

Directory(), FileSeek(), FileAttr(), FileDate(), FileSize(), FileTime(), HB_FileMatch()

FileTime

FileTime

Determines a file’s time

Syntax

      FileTime([<cFileMap>, [<nFileAttr>]]) --> <cFileClockTime>

Arguments

<cFileMap> : Designates the file name, including the path and drive designation.

<nFileAttr> : Designates the file attribute explained in the table below. The default value is 0.

() : If the function is called without parameters, it returns the file time from the current FileSeek() buffer.

Returns

<cFileClockTime> : the clock time for the <cFileMap>; the clock time from the FileSeek() buffer (when called without parameters), or a null string.

Description

Implement FileTime() alone or in conjunction with FileSeek(). If the function is called with the <cFileMap> parameter, it returns the time of the first entry found. If no matching entry is available, a null string is returned.

When called without parameters, FileTime() returns the clock time of the last file found with FileSeek(). You can also determine the clock time of file groups (wildcards) when the function is used in conjunction with FileSeek().

You can designate the attribute for the desired file in numeric form:

          Coding the File Attribute
          ---------------------------------------------------------------
          Value   Symb. constants     Assigned attribute
          ---------------------------------------------------------------
          0       FA_NORMAL
          1       FA_READONLY         READ ONLY (Read-only)
          2       FA_HIDDEN           HIDDEN (Hidden files)
          4       FA_SYSTEM           SYSTEM (System files)
          16      FA_DIRECTORY        (Subdirectory)
          32      FA_ARCHIVE          ARCHIVE (Changes since last backup)
          ---------------------------------------------------------------

Only the SYSTEM, HIDDEN, VOLUME, or DIR attributes must be specified for an entry to be found. If multiple attributes are implemented simultaneously, the table values are added accordingly. Of course, not all combinations are useful.

Examples

      .  The clock time of a particular file:

         ? FileTime("C:\TEXT\TEXT.TXT")      // File clock time or ""

      .  The clock time of an ARCHIVE/HIDDEN file:

         ? FileTime("C:\HIDE.TXT", 34")      // File clock time or ""

      .  Used in conjunction with FileSeek():

         cFile  :=  FileSeek(C:\TEXT.TXT")
         DO WHILE .NOT. EMPTY(cFile)
            ? cFile, FileTime()              // File name and clock time
            cFile  := FileSeek()             // Search for next entry
         ENDDO

Seealso

FileSeek(), FileAttr(), FileDate(), FileSize()

FileSize

FileSize

Determines the size of a file

Syntax

      FileSize([<cFileMap>, [<FileAttr>]]) --> <nFileSiz>

Arguments

<cFileMap> : Designates the file name, path, and drive designation.

<FileAttr> : Designates the file attribute that is explained in the table below. The default value is 0. () : If the function is called without parameters, it returns the file size from the current FileSeek() buffer.

Returns

<nFileSiz> : a numeric value designated file’s size, the size from the FileSeek() buffer (when called without a parameter), or -1.

Description

Implement FileSize() alone or in conjunction with FileSeek(). If the function is called with the <cFileMap> parameter, it returns the size of the first entry found. If no matching entry is available, then a value of -1 is returned

When called without parameters, FileSize() returns the size of the most recent file found with FileSeek(). Used in conjunction with FileSeek(), you can also determine the size of file groups (wildcards).

You can designate the attribute for the desired file in numeric form:

          Coding the File Attribute
          ----------------------------------------------------------------
          Value   Symb. constants     Assigned attribute
          ----------------------------------------------------------------
          0       FA_NORMAL
          1       FA_READONLY         READ ONLY (Read-only)
          2       FA_HIDDEN           HIDDEN (Hidden files)
          4       FA_SYSTEM           SYSTEM (System files)
          32      FA_ARCHIVE          ARCHIVE (Changes since last backup.)
          ----------------------------------------------------------------

Specify only the SYSTEM, HIDDEN, VOLUME, or DIR attributes for an entry to be found. If multiple attributes are implemented simul-taneously, the table values are added accordingly. Of course, not all combinations are useful.

Examples

      .  Show the size of a particular file:

         ? FileSize("C:\TEXT\TEXT.TXT")      // File size or -1

      .  The size of an ARCHIVE/HIDDEN file:

         ? FileSize("C:\HIDE.TXT", 34")      // File size or -1

      .  Used in conjunction with FileSeek():

         cFile  :=  FileSeek(C:\TEXT.TXT")
         DO WHILE .NOT. EMPTY(cFile)
            ? cFile, FileSize()              // File name and size
            cFile  := FileSeek()             // Search for next entry
         ENDDO

Seealso

FileSeek(), FileAttr(), FileDate(), FileTime()

FileDate

FileDate

Determines the file date

Syntax

      FileDate([<cFileMap>, [<nFileAttr>]]) --> <dFileDate>

Arguments

<cFileMap> : Designates a file name, including its path and drive designation. <nFileAttr> : Designates the file attribute explained in the table below. The default value is 0. () If you call this function without parameters, it returns the file date from the current FileSeek() buffer.

Returns

<dFileDate> : the date of the searched for entry, the date from the FileSeek() buffer (when called without parameters), or an empty date.

Description

You can implement FileDate() alone or in conjunction with FileSeek(). If you use the <cFileMap> parameter to call this function, it returns the date of the first entry found. If a suitable entry is not present, an empty date is returned.

When called without parameters, FileDate() returns the date of the last file it located with FileSeek(). You could also determine the dates for a file group (wildcards), when used it in conjunction with FileSeek().

The attribute for the desired file can be specified in numeric form:

          Coding the File Attribute
          ---------------------------------------------------------------
          Value   Symb. constants     Assigned attribute
          ---------------------------------------------------------------
          0       FA_NORMAL
          1       FA_READONLY         READ ONLY (Read-only)
          2       FA_HIDDEN           HIDDEN (Hidden files)
          4       FA_SYSTEM           SYSTEM (System files)
          16      FA_DIRECTORY        DIR (Directory)
          32      FA_ARCHIVE          ARCHIVE (Changes since last backup)
          ---------------------------------------------------------------

To find a file, specify only the SYSTEM, HIDDEN, VOLUME, or DIR attributes. If multiple attributes are implemented simultaneously, the table values are added accordingly. Of course, not all combinations are useful.

Examples

      .  Show the date of a particular file:

         ? FileDate("C:\TEXT\TEXT.TXT")     // The date

      .  The date of an ARCHIVE/HIDDEN file:

         ? FileDate("C:\HIDE.TXT", 34)      // The date

      .  Used in conjunction with FileSeek():

         cFile  :=  FileSeek("C:\TEXT\*.TXT")
         DO WHILE .NOT. EMPTY(cFile)
            ? cFile, FileDate()             // Name & date of file
            cFile  :=  FileSeek()           // Search for next entry
         ENDDO

Seealso

FileSeek(), FileAttr(), FileSize(), FileTime()

FileAttr

FileAttr

Determines a file’s attributes

Syntax

      FileAttr([<cFile>]) --> <nFileAttr>

Argument

<cFile> : File name, including the path and drive designation.

Returns

<nFileAttr> : a numeric value for file attributes

Description

FileAttr() is implemented alone or in conjunction with FileSeek(). If the function is called with the <cFile> parameter, it returns the attribute of the first entry found. If no acceptable entry is available, a value of 0 is returned.

When called without a parameter, FileAttr() returns the attribute for the most-recent file located with FileSeek(). When used with FileSeek(), you can determine the attribute for file groups (wildcards).

When you call FileAttr() with the <cFile> parameter, the function internally passes 63 (all attributes) as a mask. When used in conjunction with FileSeek(), you should also designate all 63 as an attribute mask, if all files are to be acknowledged.

          Coding the File Attribute
          -------------------------------------------------------------
          Value   Symb. constants     Assigned attribute
          -------------------------------------------------------------
          0       FA_NORMAL
          1       FA_READONLY         READ ONLY (Read-only)
          2       FA_HIDDEN           HIDDEN (Hidden files)
          4       FA_SYSTEM           SYSTEM (System files)
          8       FA_VOLUME           VOLUME (Name of a floppy/hard disk)
          16      FA_DIRECTORY        DIR (Directory)
          32      FA_ARCHIVE          ARCHIVE (Changes since last backup)
          ---------------------------------------------------------------

If multiple attributes are implemented for a file, the value of each corresponding attribute is added.

Examples

      .  Show the attribute of a specific file:

         ? FileAttr("C:\TEXT\TEXT.TXT")      // 32  ARCHIVE

      .  The attribute for an ARCHIVE/HIDDEN file:

         ? FileAttr("C\HIDE.TXT")            // 34  HIDDEN + ARCHIVE

      .  Used in conjunction with FileSeek():

         cFile  :=  FileSeek("C:\TEXT\TEXT.TXT")
         DO WHILE .NOT. EMPTY (cFile)
            ? cFile, FileAttr()              // Name & file attribute
            cFile  :=  FileSeek()            // Search for next entry
         ENDDO

Seealso

FileSeek(), FileDate(), FileSize(), FileTime()