If there is only one file in a folder, can I pick it up without knowing its name or iterating through the files in the folder?
(The code is VBS, but it could be anything, the FSO is the interesting part here.)
This didn't work for me:
dim fso
set fso = CreateObject("Scripting.FileSystemObject")
dim myFolder
Set myFolder = fso.getFolder("E:\test")
Dim myfiles
Set myfiles = myFolder.Files
WScript.Echo myfiles.Item(0).Path
Neither did WScript.Echo myfiles(0).Path
work. (Index 0,1 tested, both fail.)
Using a for each to get just one file seems a bit of an overkill. Also, am I not supposed to be able to somehow iterate with a simple For
loop, not a For Each
? So there must be indexes... I just can't seem to find them.