HB_DirScan

HB_DirScan

Scan a directory tree and build a files and folders list

Syntax

      HB_DirScan( <cPath>, <cFileMask>, <cAttributes> ) --> <aDirsAndFiles>

Arguments

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

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

<cAttributes> : 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 <cAttributes>. For add directories to the list add ‘D’ to <cAttributes>.

Attributes for HB_DirScan() :

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

Returns

<aDirsAndFiles> : A two-dimensional array of five columns; holding information about files in the <cPath> and the that match <cFileMask>. 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 <cPath>. And second difference is Directory() don’t requires <cFileMask> parameter, instead this info included in the <cPath>.

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
         runDiz.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

Advertisements

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

IsDirectory

IsDirectory

Tests for the existence of directories

Syntax

      IsDirectory( <cDirName> ) --> <lIsDirectory>

Arguments

<cDirName> : A character string holding the relative or absolute name of a directory.

Return

<lIsDirectory> : .T. (true) when the directory <cDirSpec> exists, otherwise .F. (false) is returned.

Description

The IsDirectory() function is used to check if a directory exists that matches the specification <cDirSpec>.

This is a character string containing the absolute or relative path of a directory.

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

      ? IsDirectory( 'C:\' )                        //  .F.
      ? IsDirectory( 'C:\*.*' )                     //  .F.
      ? IsDirectory( 'C:\temp\*.*' )                //  .T.
      ? IsDirectory( 'C:\temp\*.' )                 //  .T.
      ? IsDirectory( 'C:\temp\test*.*' )            //  .F.
      ? IsDirectory( 'C:\temp\test.bat' )           //  .F.
      ? IsDirectory( 'C:\temp\Dir' )                //  .F.
      ? IsDirectory( 'C:\temp\Dir*.*' )             //  .T.
      ? IsDirectory( 'C:\temp\Dir1' )               //  .T.
      ? IsDirectory( 'C:\temp\Dir1*' )              //  .T.
      ? IsDirectory( 'C:\temp\Dir2' )               //  .T.
      ? IsDirectory( 'C:\temp\Dir2*' )              //  .T.
      ? IsDirectory( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? IsDirectory( 'C:\temp\Dir1\test1.bat' )     //  .F.
      ? IsDirectory( 'C:\temp\Dir1\*.bat' )         //  .F.

Seealso

Directory(), File(), IsDir(), HB_FileExists(), HB_FNameExists(), HB_DirExists()

IsDir

IsDir

Tests for the existence of directories

Syntax

      IsDir( <cDirName> ) --> <lIsDirectory>

Arguments

<cDirName> : A character string holding the relative or absolute name of a directory.

Return

<lIsDirectory> : .T. (true) when the directory <cDirSpec> exists, otherwise .F. (false) is returned.

Description

The IsDir() function is used to check if a directory exists that matches the specification <cDirSpec>.

This is a character string containing the absolute or relative path of a directory.

Note

IsDir() is name abreviated version of IsDirectory()

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

      ? IsDir( 'C:\' )                        //  .F.
      ? IsDir( 'C:\*.*' )                     //  .F.
      ? IsDir( 'C:\temp\*.*' )                //  .T.
      ? IsDir( 'C:\temp\*.' )                 //  .T.
      ? IsDir( 'C:\temp\test*.*' )            //  .F.
      ? IsDir( 'C:\temp\test.bat' )           //  .F.
      ? IsDir( 'C:\temp\Dir' )                //  .F.
      ? IsDir( 'C:\temp\Dir*.*' )             //  .T.
      ? IsDir( 'C:\temp\Dir1' )               //  .T.
      ? IsDir( 'C:\temp\Dir1*' )              //  .T.
      ? IsDir( 'C:\temp\Dir2' )               //  .T.
      ? IsDir( 'C:\temp\Dir2*' )              //  .T.
      ? IsDir( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? IsDir( 'C:\temp\Dir1\test1.bat' )     //  .F.
      ? IsDir( 'C:\temp\Dir1\*.bat' )         //  .F.

Seealso

Directory(), File(), IsDirectory(), HB_FileExists(), HB_FNameExists(), HB_DirExists()

HB_FNameExists

HB_FNameExists

Tests for the existence of a file or a directory

Syntax

      File( <cFileSpec> ) --> lExists

Argument

<cFileSpec> : Exact file name to find

Returns

<lExists> : true (.T.) if the file exists or logical false (.F.)

Description

This function return a logical true (.T.) if the given filename <cFileSpec> exist

Note

HB_FNameExists() don’t accept wildcard characters

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

      ? HB_FNameExists( 'C:\' )                        //  .T.
      ? HB_FNameExists( 'C:\*.*' )                     //  .F.
      ? HB_FNameExists( 'C:\temp\*.*' )                //  .F.
      ? HB_FNameExists( 'C:\temp\*.' )                 //  .F.
      ? HB_FNameExists( 'C:\temp\test*.*' )            //  .F.
      ? HB_FNameExists( 'C:\temp\test.bat' )           //  .T.
      ? HB_FNameExists( 'C:\temp\Dir' )                //  .F.
      ? HB_FNameExists( 'C:\temp\Dir*.*' )             //  .F.
      ? HB_FNameExists( 'C:\temp\Dir1' )               //  .T.
      ? HB_FNameExists( 'C:\temp\Dir1*' )              //  .F.
      ? HB_FNameExists( 'C:\temp\Dir2' )               //  .T.
      ? HB_FNameExists( 'C:\temp\Dir2*' )              //  .F.
      ? HB_FNameExists( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? HB_FNameExists( 'C:\temp\Dir1\test1.bat' )     //  .T.
      ? HB_FNameExists( 'C:\temp\Dir1\*.bat' )         //  .F.

File

Library is rtl

Seealso:

SET DEFAULT, SET PATH, SET(), Directory(), File(), IsDirectory(), IsDir(), HB_FileExists(), HB_DirExists()

HB_FileExists

HB_FileExists

Tests for the existence of a file

Syntax

      HB_FileExists( <cFileSpec> ) --> <lExist>

Arguments

<cFileSpec> : A character string holding the relative or absolute name of a file

Return

<lFileExist> : .T. (true) when the file <cFileSpec> exists, otherwise .F. (false) is returned.

Description

The HB_FileExists() function is used to check if a file exists that matches the specification <lFileExist>.

This is a character string containing the absolute or relative path of a file.

Note

HB_FileExists() is a Harbour level function to check for the existence of a file. This works better than FILE() in most situations, but it doesn’t accept any wildcards.

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

      ? HB_FileExists( 'C:\' )                        //  .F.
      ? HB_FileExists( 'C:\*.*' )                     //  .F.
      ? HB_FileExists( 'C:\temp\*.*' )                //  .F.
      ? HB_FileExists( 'C:\temp\*.' )                 //  .F.
      ? HB_FileExists( 'C:\temp\test*.*' )            //  .F.
      ? HB_FileExists( 'C:\temp\test.bat' )           //  .T.
      ? HB_FileExists( 'C:\temp\Dir' )                //  .F.
      ? HB_FileExists( 'C:\temp\Dir*.*' )             //  .F.
      ? HB_FileExists( 'C:\temp\Dir1' )               //  .F.
      ? HB_FileExists( 'C:\temp\Dir1*' )              //  .F.
      ? HB_FileExists( 'C:\temp\Dir2' )               //  .F.
      ? HB_FileExists( 'C:\temp\Dir2*' )              //  .F.
      ? HB_FileExists( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? HB_FileExists( 'C:\temp\Dir1\test1.bat' )     //  .T.
      ? HB_FileExists( 'C:\temp\Dir1\*.bat' )         //  .F.

Seealso

SET DEFAULT, SET PATH, SET(), Directory(), File(),  IsDirectory(), IsDir(), HB_FNameExists(), HB_DirExists()

HB_DirExists

HB_DirExists

Tests for the existence of a directory

Syntax

      HB_DirExists( <cDirName> ) --> <lIsDirectory>

Arguments

<cDirName> : A character string holding the relative or absolute name of a directory.

Return

<lIsDirectory> : .T. (true) when the directory <cDirName> exists, otherwise .F. (false) is returned.

Description

The HB_DirExists() function is used to check if a directory exists that matches the specification <cDirName>.

This is a character string containing the absolute or relative path of a directory.

Note

HB_DirExists() don’t accept wildcard characters

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

      ? HB_DirExists( 'C:\' )                        //  .T.
      ? HB_DirExists( 'C:\*.*' )                     //  .F.
      ? HB_DirExists( 'C:\temp\*.*' )                //  .F.
      ? HB_DirExists( 'C:\temp\*.' )                 //  .F.
      ? HB_DirExists( 'C:\temp\test*.*' )            //  .F.
      ? HB_DirExists( 'C:\temp\test.bat' )           //  .F.
      ? HB_DirExists( 'C:\temp\Dir' )                //  .F.
      ? HB_DirExists( 'C:\temp\Dir*.*' )             //  .F.
      ? HB_DirExists( 'C:\temp\Dir1' )               //  .T.
      ? HB_DirExists( 'C:\temp\Dir1*' )              //  .F.
      ? HB_DirExists( 'C:\temp\Dir2' )               //  .T.
      ? HB_DirExists( 'C:\temp\Dir2*' )              //  .F.
      ? HB_DirExists( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? HB_DirExists( 'C:\temp\Dir1\test1.bat' )     //  .F.
      ? HB_DirExists( 'C:\temp\Dir1\*.bat' )         //  .F.

Seealso

Directory(), File(), IsDir(), IsDirectory(), HB_FileExists(), HB_FNameExists()