Get File Names Method
The Get File Names method is a standard Visual Basic method that returns the first file name it finds that matches the value in the pathname argument and that possesses the attributes that you specify in the attributes argument. If it does not find a file, then it returns a null string ("").
Format
Dir[$] [(pathname[, attributes])]
For information about the dollar sign, see Usage of the Dollar Sign.
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
pathname |
A string or string expression that evaluates to a path or file name. |
attributes |
An integer expression that specifies the file attributes to choose. |
Usage for the Attributes Argument
You can use the integer values for the attributes argument described in the following table to return a specific type of file.
Value in Attributes Argument | File Type |
---|---|
0 (default) |
Normal files with no attributes set. |
2 |
Normal and hidden files. |
4 |
Normal and system files. |
8 |
Volume label only. |
16 |
Normal files and directories. |
You can add values to choose multiple attributes. For example, to return normal files, hidden files, and system files, you set the attributes argument to 6, where 6 equals 0 plus 2 plus 4.
If you set the attributes argument to 8, then this method returns one of the following values:
The volume label of the drive that you specify in the pathname argument.
The current drive if you do not specify a drive in the pathname argument.
Usage for the Pathname Argument
The pathname argument can include a drive specification and the following wildcard characters:
? (question mark)
* (asterisk)
Siebel VB interprets a null string ("") in the pathname argument as the current directory. This value is equivalent to a period (.). You can use the Get File Names method again to get more matching file names, but this time do not include the pathname argument or the attributes argument.
Example
The following example lists all the files that reside on drive A:
Sub Button_Click
Dim msgReturn
Dim directory, count
Dim x, msgtext
Dim A()
count = 1
ReDim A(100)
directory = Dir ("A:\*.*")
Do While directory <> ""
A(count) = directory
Count = count + 1
directory = Dir
loop
msgtext = "Contents of drive A:\ is:" & Chr(10) & Chr(10)
For x = 1 to count
msgtext = msgtext & A(x) & Chr(10)
Next x
End Sub