List the files in a folder.
Syntax Dir [( path [, attributes ] ) ] Key path Path to a file, folder, or directory. If the path is not found, dir will return a zero-length string. attributes The sum of the file attributes. One or a combination of the following values:
0 vbNormal (Default)
1 vbReadOnly
2 vbHidden
4 vbSystem System file
8 vbVolume Volume label
16 vbDirectory
64 vbAlias
Wildcards * and ? can be used to return multiple files.
To test if a folder (or server) exists at all, you can use this function from Allen Browne
Function FolderExists(strPath As String) As Boolean On Error Resume Next FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory) End Function
Examples
'List a filename Dir("C:\docs\demo.xls") 'Check if a file exists If Len(Dir("C:\docs\demo.xls")) = 0 Then Msgbox "File not found!" 'Check if a folder exists If Len(Dir("C:\docs", vbDirectory)) = 0 Then Msgbox "Folder not found!"
“Is not the whole world a vast house of assignation of which the filing system has been lost?” ~ Quentin Crisp
Related:
MkDir - Create directory