Jamie Garroch - MVP
Jamie Garroch - MVP

Reputation: 2979

VBA.Dir and FileSystemObject fail to correctly return Files.Count for a OneDrive folder

I have some automation code which recursively processes a folder structure in a local OneDrive for Business folder here: %UserProfile%\SPO_Domain\Site\Library

There are hundreds of folders and thousands of files.

In one folder this simple command structure fails to return the right number of files, which is 280 in my example:

CreateObject("Scripting.FileSystemObject").GetFolder(path).Files.Count

It incorrectly returns 200. The VBA.Dir function also fails at exactly the same point in the folder, at 200 files with this code structure:

file = Dir(PATH)

Do While file <> ""
    x = x + 1
    Debug.Print x, file
    file = Dir()
Loop

It fails on the 201st Dir() call with error 5 "Invalid procedure call or argument" which is the behaviour when you call Dir() after it previously returns a zero-length string ("") once the last file is returned.

Other folders with more than 200 files work as expected.

If I copy the entire folder to a C:\Temp location, both the FSO and DIR methods work as expected.

What could possibly cause this behaviour?

Upvotes: 1

Views: 382

Answers (0)

Related Questions