The Windows XP kernel does not turn every call into
FindNextFile into a packet on the network. Rather, the first time an application calls
FindNextFile, it issues a bulk query to the server and returns the first result to the application. Thereafter, when an application calls
FindNextFile, it returns the next result from the buffer. If the buffer is empty, then
FindNextFile issues a new bulk query to re-fill the buffer.
This is a significant performance improvement when reading the entire contents of large directories because it reduces the number of round trips to the server. We'll see next time that the gain can be quite significant on certain types of servers.
But it also means that the suggestion of "Well, why not ask for 101 files and see if you get an error" won't help any. (Actually I think the magic number was really 128, not 100, but let's keep calling it 100 since that's what I started with.) The number 100 was not some magic value on the server. That number was actually our own unwitting choice: The bulk query asks for 100 files at a time! If we changed the bulk query to ask for 101 files, then the problem would just appear at the 102nd file.