The FileSystemObject VBA FolderExists method returns True if the folder exists otherwise it will return False.
- BuildPath
- CopyFile
- CopyFolder
- CreateFolder
- CreateTextFile
- DeleteFile
- DeleteFolder
- DriveExists
- FileExists
- FolderExists
- GetAbsolutePathName
- GetBaseName
- GetDrive
- GetDriveName
- GetExtensionName
- GetFile
- GetFileName
- GetFolder
- GetParentFolderName
- GetSpecialFolder
- GetTempName
- MoveFile
- MoveFolder
- OpenTextFile
VBA FolderExists
1 | fso.FolderExits( folderpath ) |
folderpath
A string representing path to the folder.
VBA FolderExists Examples
Below examples assume file “C:\Src\Subfolder” exists and no other folders exist in “C:\Src”.
1 2 3 4 5 | Set fso = CreateObject( "Scripting.FileSystemObject" ) Debug.Print fso.FileExists( "C:\Src\Subfolder" ) 'Result: True Debug.Print fso.FileExists( "C:\Src\Other" ) 'Result: False |
Alternatives in Windows
You can also check if the Folder exists in Windows using:
- CMD EXIST statement – see example below 1
if exist "C:\Somefolder\" (echo "File found" ) else (echo "File not found")
- Powershell Test-Path command – see Microsoft documentation here