How to move or delete files from a folder containing 2 million files on an NTFS drive

ntfswindows-server-2003

The issue is that any modification to the directory locks up Explorer indefinitely, though Samba access to other directories still works. I've tried moving files locally and over Samba.

Even enumerating the directory to get the list of files locks up the computer indefinitely.

I tried using Python's win32file.FindFilesIterator to iterate the files but that also hangs.

My idea was to move each file to a different directory (in a directory above the directory we're dealing with) based on its timestamp, so that we'd have at most a thousand or so files in each directory… But since I can't even enumerate the files, that's been a non-starter.

If I have to give up and just nuke the directory I'm willing to do that, but a standard delete also hangs indefinitely.

I have set these two parameters to increase speed and they also did not help the issue:

R:\>fsutil behavior query disablelastaccess
disablelastaccess = 1

R:\>fsutil behavior query disable8dot3
disable8dot3 = 1

These are all sequential images that would have run into the 'bug' with 8.3 filenames whereby many similarly named files in one directory can take a long time to compute 8.3 filenames. From what I understand this data is stored in the file system even after disable8dot3 is enabled, so it may still be contributing to the problem.

Any ideas?

Best Answer

Depending on how the files were added and how badly the folder is fragmented the quickest way might even be to move off the files you want to keep and nuke the partition!