Dir
Returns a String representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.Syntax: Dir[(pathname[, attributes])]
The Dir function syntax has these parts:
| Part | Description |
| pathname | Optional. String expression that specifies a file name — may include directory or folder, and drive. A zero-length string ("") is returned if pathname is not found. |
| attributes | Optional. Constant or numeric expression, whose sum specifies file attributes. If omitted, returns files that match pathname but have no attributes. |
Settings
The attributes argument settings are:
| Constant | Value | Description |
| vbNormal | 0 | (Default) Specifies files with no attributes. |
| vbReadOnly | 1 | Specifies read-only files in addition to files with no attributes. |
| vbHidden | 2 | Specifies Hidden files in addition to files with no attributes. |
| VbSystem | 4 | Specifies System files in addition to files with no attributes Not Available on the Macintosh.. |
| vbVolume | 8 | Specifies volume label; if any other attributed is specified, vbVolume is ignored. not available on the Macintosh. |
| vbDirectory | 16 | Specifies directories or folders in addition to files with attributes. |
| vbAlias | 64 | Specified file name is an alias. Available only on the Macintosh. |
Note These constants are specified by Visual Basic for Applications and can be used anywhere in your code in place of the actual values.
Example:
If Dir("c:\windows\win.ini") = "win.ini" Then
MsgBox "File exists"
Else
MsgBox "File does not exist"
End If
MsgBox "File exists"
Else
MsgBox "File does not exist"
End If
ChDir
Changes the current directory or folder.Syntax
ChDir path
The required path argument is a string expression that identifies which directory or folder becomes the new default directory or folder. The path may include the drive. If no drive is specified, ChDir changes the default directory or folder on the current drive.
Remarks
The ChDir statement changes the default directory but not the default drive. For example, if the default drive is C, the following statement changes the default directory on drive D, but C remains the default drive.
Example:
Dim Path as string
Dir(“C:\NewFolder”) = Path
Path = ChDir(“C:\MyFolder”
Dir(“C:\NewFolder”) = Path
Path = ChDir(“C:\MyFolder”
ChDrive
Changes the current drive.Syntax: ChDrive drive
The required drive argument is a string expression that specifies an existing drive. If you supply a zero-length string (""), the current drive doesn't change. If the drive argument is a multiple-character string, ChDrive uses only the first letter.
Example:
ChDrive "D" ' Make "D" the current drive.


