FileList (statement)

Syntax

FileList array() [,[filespec$] [,[include_attr] [,exclude_attr]]]

Description

Fills a String or Variant array with filenames from disk.

Comments

The FileList function takes the following parameters:

 

Parameter

Description

 

Array()

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.

 

Filespec$

String specifying which filenames are to be included in the list.

The filespec$ parameter can include wildcards, such as * and ?. If this parameter is omitted, then * is used.

 

Include_attr

Integer specifying attributes of files you want included in the list. It can be any combination of the attributes listed below.

If this parameter is omitted, then the value 97 is used (ebReadOnly Or ebArchive Or ebNone).

 

Exclude_attr

Integer specifying attributes of files you want excluded from the list. It can be any combination of the attributes listed below.

If this parameter is omitted, then the value 18 is used (ebHidden Or ebDirectory). In other words, hidden files and subdirectories are excluded from the list.

 

Wildcards

The * character matches any sequence of zero or more characters, whereas the ? character matches any single character. Multiple *'s and ?'s can appear within the expression to form complete searching patterns. The following table shows some examples:

 

This Pattern

Matches These Files

Douesn't Match These Files

 

*S*.TXT

SAMPLE.TXT
GOOSE.TXT
SAMS.TXT

SAMPLE
SAMPLE.DAT

 

C*T.TXT

CAT.TXT

CAP.TXT
ACATS.TXT

 

C*T

CAT
CAP.TXT

CAT.DOC

 

C?T

CAT
CUT

CAT.TXT
CAPIT
CT

 

*

(All files)

 

 

File Attributes

These numbers can be any combination of the following:

 

Constant

Value

Includes

 

EbNormal

0

Read-only, archive, subdir, none

 

EbReadOnly

1

Read-only files

 

EbHidden

2

Hidden files

 

EbSystem

4

System files

 

EbVolume

8

Volume label

 

EbDirectory

16

DOS subdirectories

 

EbArchive

32

Files that have changed since the last backup

 

EbNone

64

Files with no attributes

Example

This example fills an array a with the directory of the current drive for all files that have normal or no attributes and excludes those with system attributes. The dialog box displays four filenames from the array.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  Dim a$()
  FileList a$,"*.*",(ebNormal + ebNone),ebSystem
  If ArrayDims(a$) > 0 Then
    r = SelectBox("FileList","The files you filtered are:",a$)
  Else
    MsgBox "No files found."
  End If
End Sub

See Also

FileDirs (statement); Dir, Dir$ (functions).

More information

F