I'm writing a vbscript function that looks something like this:
Public Function fnGetXLSFileCount()
Dim fso, src, folder, file, fileList
Set fileList = CreateObject("System.Collections.ArrayList")
Set fso = CreateObject("Scripting.FileSystemObject")
src = "\\myserver\myfolder"
Set folder = fso.GetFolder(src)
For Each file In folder.files
If LCase(fso.GetExtensionName(file)) = "xlsx" Then
fileList.Add file.name
End If
Next
Set fnGetXLSFileCount = fileList
End Function
As you can see I'm creating an ArrayList and then adding all the names of excel files that exist in a specified folder.
I then call this function and use the Set operator to specify that I'm expecting an object to be returned.
Set XLSFileList = fnGetXLSFileCount
When I check the count on the object it seems to be correct. When I try to pull the names out there is nothing there. What am I doing incorrectly here?
For each file in XLSFileList
name = file.Item(0)
Next