Directory

Directory

Build an array of Directory and file information

Syntax

      Directory( <cDirSpec>, [<cAttributes>] ) --> aDirectory

Arguments

<cDirSpec> : identifies the drive, Directory and file specification for the Directory search. Wildcards are allowed in the file specification. If <cDirSpec> is omitted, the default value is *.*.

<cAttributes> : specifies inclusion of files with special attributes in the returned information. <cAttributes> is a string containing one or more of the following characters:

          Directory() Attributes
          ---------------------------------------------------------
          Attribute Meaning
          ---------------------------------------------------------
              H     Include hidden files
              S     Include system files
              D     Include directories
              V     Search for the DOS volume label and exclude all
                    other files
          ---------------------------------------------------------

Normal files are always included in the search, unless you specify V.

Returns

Directory() returns an array of subarrays, with each subarray containing information about each file matching <cDirSpec>. The subarray has the following structure:

          Directory() Subarray Structure
          ----------------------------------------------------------
          Position Metasymbol  Directry.ch
          ----------------------------------------------------------
             1     cName       F_NAME
             2     cSize       F_SIZE
             3     dDate       F_DATE
             4     cTime       F_TIME
             5     cAttributes F_ATTR
          ----------------------------------------------------------

If no files are found matching <cDirSpec> or if <cDirSpec> is an illegal path or file specification, Directory() returns an empty ({}) array.

Description

Directory() is an environment function that returns information about files in the current or specified Directory. It is similar to ADIR(), but returns a single array instead of adding values to a series of existing arrays passed by reference. Use Directory() to perform actions on groups of files. In combination with AEVAL(), you can define a block that can be applied to all files matching the specified <cDirSpec>. The header file, Directry.ch, in the \CLIP53\INCLUDE subDirectory contains #defines for the subarray subscripts, so that the references to each file subarray are more readable.

Examples

      This example creates an array of information about files in the current
      Directory and then lists the names of the files using AEVAL() and QOUT():

      #include "Directry.ch"
      //
      aDirectory := Directory("*.*", "D")
      AEVAL( aDirectory, {| aFile | QOUT( aFile[ F_NAME ])} )

      #include "Directry.ch"

      PROC Main()

         LOCAL cFileSpec := "C:\hb32\*.*"

         LOCAL aFileList := Directory( cFileSpec, "D")

          LOCAL nMaxFNmLen := 0

         SET CENT ON
         SET DATE GERM

         AEVAL( aFileList, { | a1File | nMaxFNmLen := ;
                             MAX( nMaxFNmLen, LEN( a1File[ F_NAME ] ) ) } )

         AEVAL( aFileList, { | a1File | ;
                             QOUT( PADR( a1File[ F_NAME ], nMaxFNmLen + 1 ),;
                             TRAN( a1File[ F_SIZE ], "999,999,999" ),;
                             a1File[ F_DATE ],;
                             a1File[ F_TIME ],;
                             a1File[ F_ATTR ] ) } )

         ?
         WAIT "End of Directory.prg"

      RETU // Directory.Main()

      Result of Directory.prg :

      .                   0 13.09.2012 02:07:15 D
      ..                  0 13.09.2012 02:07:15 D
      addons              0 13.09.2012 02:07:07 D
      bin                 0 13.09.2012 02:07:12 D
      ChangeLog   8,848,829 12.09.2012 01:59:44 A
      comp                0 13.09.2012 02:07:12 D
      contrib             0 13.09.2012 02:07:16 D
      COPYING        47,456 12.09.2012 01:59:44 A
      doc                 0 13.09.2012 02:07:07 D
      extras              0 13.09.2012 02:07:15 D
      include             0 13.09.2012 02:07:07 D
      INSTALL        79,968 12.09.2012 01:59:44 A
      lib                 0 13.09.2012 02:07:14 D
      NEWS          108,058 12.09.2012 01:59:44 A
      RELNOTES        9,832 18.04.2012 04:00:10 A
      tests               0 13.09.2012 02:07:15 D
      TODO            2,924 12.09.2012 01:59:44 A
      uninstall.exe 104,646 13.09.2012 02:07:12 A

      End of Directory.prg

Seealso

ADir(), FileSeek(), HB_FileMatch()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.