Dir

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.

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


© Copyright SS64.com 1999-2014
Some rights reserved