2

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
bobble14988
  • 1,749
  • 5
  • 26
  • 38

2 Answers2

5

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.

1

Take a look at the Filesystem Object (FSO). It sports methods such as FileExists() and FolderExists().

Lumi
  • 14,775
  • 8
  • 59
  • 92
  • But with those you have to check for a specified file which is not what I want to do. I wanted to check if ANY file existed. Thanks anyway. – bobble14988 Jul 20 '11 at 09:08