Foldy

Fast file search on every kind of Windows drive: six methods, one per drive type

· CHA SEONG HYUN

Fast file-name search on Windows needs a list (an index) built ahead of time. But each kind of drive allows different methods: NTFS on this PC, a PC without admin rights, USB sticks and memory cards, company and network drives, and cloud drives. Here is how to build that list on each of them quickly, without putting sudden load on the PC or the server.

0) First, the structure: split C# and Rust by role

The rule set in the original design was “a file explorer’s bottleneck is I/O and drawing, not the language”. So the languages were split by job, not by speed.

1) NTFS: read $MFT instead of opening folders

NTFS keeps a table of every file ($MFT). Instead of opening each folder, read that table sequentially in 4–16 MB chunks and you get name, parent, size and timestamps in one pass: about 12 seconds for 1.8 million files. After that, follow the USN journal (the record of creates, deletes and renames).

2) Without admin rights: read the USN journal as a normal user

Only administrators can read $MFT. But a normal user can call FSCTL_READ_UNPRIVILEGED_USN_JOURNAL on a handle to C:\. So re-read only folders whose contents changed since the last full pass and keep the previous list for the rest. A C: re-check went from 23 to 9 seconds (7 of 250,000 folders re-read).

3) Read less using folder times, and test whether the times can be trusted

A folder’s modified time changes only when something directly inside it changes. So for leaf folders (no subfolders), ask only for the time and reuse the previous list if it is unchanged.

4) USB sticks and memory cards: step aside instead of sleeping

For directly attached drives, read one folder at a time on a thread in Windows background mode (THREAD_MODE_BACKGROUND_BEGIN). Its disk priority goes to the back of the queue, so it yields automatically when another program uses the disk.

5) Network and company drives: measure how many to read at once

Remote drives answer slowly, so reading several folders in parallel is faster. How many depends on the server. So try 4, 8 and 16 in turn and pick the smallest count whose actual time per folder is within 125% of the best (re-measure every 300 decisions).

6) Resume after interruptions, and recognize a swapped disk

What went wrong, and the fixes

Where I implemented this

These methods are in Foldy File Manager, an open-source Windows file manager I’m building (Rust: $MFT parsing and the index service; C#: gathering other drives). Code and more detail are in the technical notes on GitHub. If you know a better way or spot a mistake, please tell me.

← Back to Foldy