Share via


ADIR( ) Function

Places information about files into an array and then returns the number of files.

ADIR(ArrayName [, cFileSkeleton [, cAttribute [, nFlag]]])

Return Value

Numeric

Parameters

  • ArrayName
    Specifies the name of the array. If the array you include doesn't exist, Visual FoxPro automatically creates the array. If the array exists and isn't large enough to contain all the information, Visual FoxPro automatically increases the size of the array to accommodate the information. If the array is larger than necessary, Visual FoxPro truncates the array. If the array exists and ADIR( ) returns 0 because no matching files are found, the array remains unchanged. If the array doesn't exist and ADIR( ) returns 0, the array isn't created.

    The following table describes the contents and data type of each column in the array:

    Column

    Array contents

    Data type

    1

    File names

    Character

    2

    File sizes

    Numeric

    3

    Dates last modified

    Date

    4

    Times last modified

    Character

    5

    File attributes

    Character

    The last array column contains the file attributes of the matching files. Each file attribute is expressed by a letter; a file can have more than one attribute. The following table indicates the file attribute represented by each letter:

    Letter

    Attribute

    A

    Archive – Read/Write

    H

    Hidden

    R

    Read-only

    S

    System

    D

    Directory

  • cFileSkeleton
    Specifies a file skeleton so you can store information about files with names or extensions that match a search criterion. For example, the criterion can be all tables, all text files, all files with names that have A as their first letter, and so on. Such general searches are done by including the wildcards * and ? in cFileSkeleton. A question mark represents a single character; an asterisk represents any number of characters. You can use any number of wildcards in any position within the file skeleton.

    You can specify a drive and/or directory to search for matching file names. If you don't specify a drive and a directory, Visual FoxPro places information about files in the current directory into the array.

  • cAttribute
    Specifies the inclusion of subdirectories and hidden or system files.

    cAttribute can contain any combination of D, H, and S. Including D returns subdirectory names of the current directory in addition to file names that match the file skeleton specified in cFileSkeleton. Including H returns information about hidden files that match the file skeleton specified in cFileSkeleton. Including S returns information about system files that match the file skeleton specified in cFileSkeleton.

    Include an empty string in cFileSkeleton to return just subdirectory names, hidden files or system files.

    You can include V in cAttribute to return the volume name of the current drive. Only the volume name is returned to the array if V is included with D, H, or S. The volume name is stored in the first array element and the remainder of the array is truncated.

  • nFlag
    Specifies whether the display provides DOS naming or actual case sensitivity.

    nFlag

    Description

    0

    (Default) Display represents the full file name in uppercase

    1

    Display represents original Case in names

    2

    Display follows DOS 8+3 naming convention

Remarks

For each file, ADIR( ) places into the array the file name, size, date last modified, time last modified, and attributes.

Example

The following example uses ADIR( ) to create an array containing database information. The names of the databases are then displayed.

CLOSE DATABASES
SET DEFAULT TO (HOME(2) + 'Data')

gnDbcnumber = ADIR(gaDatabase, '*.DBC')  && Create array

CLEAR
FOR nCount = 1 TO gnDbcnumber  && Loop for number of databases
   ? gaDatabase(nCount,1)  && Display database names
ENDFOR
SET PATH TO HOME( )  && Set path to Visual FoxPro directory

See Also

Reference

ADEL( ) Function

AELEMENT( ) Function

AFIELDS( ) Function

AINS( ) Function

ALEN( ) Function

ANETRESOURCES( ) Function

ASCAN( ) Function

ASORT( ) Function

ASUBSCRIPT( ) Function

DIMENSION Command

DIR or DIRECTORY Command

Other Resources

Functions

Language Reference (Visual FoxPro)