Dir

This method returns the name of a file, directory, or folder that matches a specified pattern or file attribute.

Syntax

file.Dir(pathname,[ attributes])

Parameters

file
Reference to a FileSystem control.
pathname
Optional. String expression that specifies a file name or path.
attributes
Optional. Numeric expression whose sum specifies file attributes. If omitted, all files that match pathname are returned. The following table describes the parameter settings of attributes.
Constant
Value
Description
fsAttrNormal 0 Normal
fsAttrReadOnly 1 Read-only
fsAttrHidden 2 Hidden
fsAttrSystem 4 System file
fsAttrVolume 8 Volume label. If specified, all other attributes are ignored.
fsAttrDirectory 16 Directory or folder
fsAttrArchive 32 Archive

Return Value

String. File name that matches pathname and attributes. Dir returns a zero-length string ("") if pathname is not found.

Remarks

Dir supports the use of multiple-character (*) and single-character (?) wildcards to specify multiple files. You must specify pathname the first time you call the Dir method. In addition, if you specify file attributes you must include pathname.

The Dir method returns the first file name that matches pathname. To get any additional file names that match pathname, call Dir again with no parameters. When no more file names match, Dir returns a zero-length string (""). Once a zero-length string is returned, you must specify pathname in subsequent calls.