Comment by magicalhippo

7 years ago

Reminds me of a performance optimization I did at work. A previous developer had implemented a routine to clean up old files. The routine would enumerate all the files in a directory, and then ask for the file age, and if old enough delete the file.

The problem was that asking the file age given a path caused an open/close, as GetFileSizeEx expects a handle.

Now, at least on Windows, enumerating a directory gets[1] you not just the filename, but a record containing filename, attributes, size, creation and access timestamps. So all I had to do was simply merge the directory enumeration and age checking.

The result was several orders of magnitudes faster, especially if the directory was on a network share.

[1]: https://docs.microsoft.com/en-us/windows/desktop/api/minwinb...