xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

ADir()

Fills pre-allocated arrays with file and/or directory information.

Syntax

ADir( [<cFileMask>], ;
      [<aName>]    , ;
      [<aSize>]    , ;
      [<aDate>]    , ;
      [<aTime>]    , ;
      [<aAttr>]      ) --> nDirEnries

Arguments

<cFileMask>
<cFileMask> is a character string specifying the directory and file mask used to search for files. The file mask may contain wild card characters, like "*" or "?". If no path is givven, ADir() searches in the SET DEFAULT directory.
<aName>
A pre-allocated array to fill with the file names of the found files. Each element contains a character string holding a file name without path information, as reported by the operating system.
<aSize>
A pre-allocated array to fill with numeric values indicating the file size.
<aDate>
A pre-allocated array to fill with the "last change" date values.
<aTime>
A pre-allocated array to fill with the "last change" Time values. The values are of data type Character and contain the time formatted as "hh:mm:ss".
<aAttr>
A pre-allocated array to fill with file attributes. Recognized attributes are Normal, Hidden, System and Directory. The are combined in one character string. If <aAttr> is omitted, ADir() includes only normal files in the search result.

Return

The function returns a numeric value indicating the number of files meeting the search condidtion defined with <cFileMask>.

Description

ADir() searches a directory for files meeting a search pattern <cFileMask>, and optionally fills arrays with various file information. The number of files meeting the search condition is usually determined in an initial call to ADir(). The return value of the initial call is then used to pre-allocate one-dimensional arrays that are filled with the desired informationin a second call to ADir().

To include files with Hidden, Directory, or System attributes, the according attribute must be specified for the search.

Note:  ADir() is a compatibility function. It is superseded by the Directory() function which returns all file information in a multi-dimensional array.

Info

See also:AChoice(), AEval(), AScan(), ASort(), Directory(), Len()
Category: Array functions , File functions
Source:rtl\adir.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// This example demonstrates the two-step approach for obtaining file
// information about .LOG files. The initial call determines the number
// of files found. This result is used to pre-allocate arrays to fill
// in a second call to ADir().

   PROCEDURE MAIN()
      LOCAL aName, aSize, aDate, aTime, aAttr
      LOCAL nLen, i

      nLen := ADir( "*.log" )

      IF nLen > 0
         aName := Array( nLen )
         aSize := Array( nLen )
         aDate := Array( nLen )
         aTime := Array( nLen )
         aAttr := Array( nLen )

         ADir( "*.log", aName, aSize, aDate, aTime, aAttr )

         FOR i := 1 TO nLen
           ? aName[i], aSize[i], aDate[i], aTime[i], aAttr[i]
         NEXT
      ELSE
         ? "This directory does not contain .log files."
      ENDIF

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe