I had a directory with ~2,500 subdirectories in it.
Viewing the folder with Windows Explorer on the LAN was a bit slow.
Viewing the folder over VPN was very very slow.

I thought this was an SMB version issue with the Server 2008 (not R2) machine, i.e. it not being very VPN friendly (VPN was my issue.. nobody notices it’s a bit slow on the LAN), and I was attempting to in-place upgrade it to 2012 as an interim to 2012 R2 (another story..)

I had tested a similar directory tree on a Server 2016 machine and it was rapido. I simply used xcopy to copy the directory structure without the contents, and used this to test.

So I was all set to upgrade the OS, get a shiny new SMB3, and …

Well the upgrade isn’t happening (component based servicing mess. This machine has had hundreds of updates on it since 2009.. nearly 9 years of updates have to be jigged about just so that Terminal Services Gateway role can be removed to allow the upgrade to Server 2012, and it’s just not happening.)

Anyway! I found out what was wrong. This is a little obscure.
About 900 folders in there had the +s attribute set! (System).

The quick clue was that ‘dir’ from a command prompt only listed about half the folders that were known to be in there.

I believe this was something I was asked to do ages ago, so that the company could make use of the ‘Comment’ field in windows explorer for folders. So I made a setComment script that tied into the explorer context menu, and read a message from you, then stored it in a Desktop.ini within the folder, and set the folder +S. It never got used because Explorer was flaky about displaying the comments.
The +S attribute makes Windows Explorer look into each folder for a Desktop.ini and process it.

So, my fix was as simple as:

for /d %a in (*) do attrib -s “%a”

(in the folder with all the subfolders).