I’m making a script to list all files within a folder.
The intention is to list all files within a specific folder on every server we have.
So I have an excel file with as first line every servername.
Of course I don’t have rights on every server or there is no scripts folder; so sometimes i get a “path not found” error.
Eventhough I used On Error Resume Next it still throws the error.
I would need something like try – catch, but that doens’t exists in vbs.
How can I try to connect to folders and ignore when there’s an error?
The offending lines is the Set folder = ...
Do While objSheet.Cells(1, intCol).Value <> ""
intRow = 2
sFolder ="\\" & objSheet.Cells(1, intCol).Value & "\C$\Scripts"
'msgbox sFolder
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
...
The full code: https://gist.github.com/076501c940e8388b5b39
You can check if a folder exists with fso.FolderExists(sFolder):