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.


Dir[$] [(pathname[, attributes])]



A string or string expression evaluating to a path or filename


An integer expression specifying the file attributes to select


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.

File Type

0 (default)

Normal files (no attributes set)


Normal and hidden files


Normal and system files


Volume label (only)


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.


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).


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
   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

See Also

ChDir Statement
ChDrive Statement
CurDir Function
MkDir Statement
RmDir Statement

Siebel VB Language Reference