How can I check if there exists a file within a folder with any name? I also want to ignore sub-folders.
Thanks.
EDIT:
Think I've got it but any contributions are also appreciated...
If Folder.Files.Count > 0 Then
'Do something
How can I check if there exists a file within a folder with any name? I also want to ignore sub-folders.
Thanks.
EDIT:
Think I've got it but any contributions are also appreciated...
If Folder.Files.Count > 0 Then
'Do something
I think you've got it, pretty much it's
Const PATH = "C:\Path\to\folder"
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
dim folder: set folder = fso.getFolder(PATH)
if folder.files.Count <> 0 then
'do something
end if
You might want to check the path is valid with FolderExists()
before the getFolder(PATH)
or catch the error if the path does not exist. The files
collection does not include subfolders.
Take a look at the Filesystem Object (FSO). It sports methods such as FileExists()
and FolderExists()
.