The FileSystemObject VBA FolderExists method returns True if the folder exists otherwise it will return False.
VBA FileSystemObject Methods
- 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
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”.
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
if exist "C:\Somefolder\" (echo "File found" ) else (echo "File not found")
- Powershell Test-Path command – see Microsoft documentation here