Siebel VB Language Reference > VB Language Reference >
Dir Function
The standard VB function Dir returns a filename that matches the specified pattern, having the specified attributes. Syntax
Dir[$] [(pathname[, attributes])]
|
|
pathname |
A string or string expression evaluating to a path or filename |
attributes |
An integer expression specifying the file attributes to select |
Returns
The first filename that matches the pathname argument and has the specified attributes. Use the following integer values for attributes to return the specified type of file.
|
|
0 (default) |
Normal files (no attributes set) |
2 |
Normal and hidden files |
4 |
Normal and system files |
8 |
Volume label (only) |
16 |
Normal files and folders |
NOTE: The values in the table can be added together to select multiple attributes. For example, to list hidden and system files in addition to normal files, set attributes to 6 (6 = 2 + 4). If attributes is set to 8, the Dir function returns the volume label of the drive specified in the pathname argument, or of the current drive if a drive is not explicitly specified.
Usage
Pathname can include a drive specification and wildcard characters (? and *). A null string ("") passed as pathname is interpreted as the current folder (the same as "."). To retrieve additional matching filenames, call the Dir function again, omitting the pathname and attributes arguments. If no file is found, a null string ("") is returned. The dollar sign ($) in the function name is optional. If it is included, the return type is string. Otherwise, the function returns a variant of vartype 8 (string). Example
This example lists the contents of the diskette in drive A. Sub Button_Click Dim msgReturn Dim folder, count Dim x, msgtext Dim A() count = 1
ReDim A(100) folder = Dir ("A:\*.*") Do While folder <> "" A(count) = folder Count = count + 1 folder = 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
Related Topics
ChDir Statement ChDrive Statement CurDir Function MkDir Statement RmDir Statement
|