FileDirs (statement)


FileDirs array() [,dirspec$]


Fills a String or Variant array with directory names from disk.


The FileDirs statement takes the following parameters:






Either a zero- or a one-dimensioned array of strings or variants. The array can be either dynamic or fixed.

If array() is dynamic, then it will be redimensioned to exactly hold the new number of elements. If there are no elements, then the array will be redimensioned to contain no dimensions. You can use the LBound, UBound, and ArrayDims functions to determine the number and size of the new array's dimensions.

If the array is fixed, each array element is first erased, then the new elements are placed into the array. If there are fewer elements than will fit in the array, then the remaining elements are initialized to zero-length strings (for String arrays) or Empty (for Variant arrays). A runtime error results if the array is too small to hold the new elements.



String containing the file search mask, such as:






If this parameter is omitted, then * is used, which fills the array with all the subdirectory names within the current directory.


This example fills an array with directory entries and displays the first one.

Sub Main()
  Dim a$()
  FileDirs a$,"c:\*"
  MsgBox "The first directory is: " & a$(0)
End Sub

See Also

FileList (statement); Dir, Dir$ (functions); CurDir, CurDir$ (functions); ChDir (statement).

More information