Question

I have a portable audio player which lists directories and files (SD card FAT32 storage), as per the manual, in the order they are copied. That is indeed what it does: when manually copying one file at a time, it will display those files in the order copied. Now I already copied hundreds of files using a combination of Windows Explorer and Unison so as a result everything gets displayed in what is basically random order. I'd like everything to be listed alphabetically, so I wrote the simplest piece of C# code I can think of that lists directories alphabetically, idem for the files inside them, and uses Directory.SetLastWriteTime and File.SetLastWriteTime to set the time on each, and that time is incremented with 2 seconds on each iteration.

Reading everything back in using GetLastWriteTime confirms the timestamps are updated, however the player does not do what would be excpected.. It does order directories correctly, and some of the files (probably those that were already copied in alphabetical order before), but not all of them. Tried everything again using SetCreationTime but the same result.

So which file property has to be set then in order to make this work? Or is it some property of the FAT drive itself? And which functions to use? (eventually plain C apis are fine as well)

Was it helpful?

Solution

fatsort claims to do this so you can study its source code to find out how to re-order files.

Note that what you want to do is a fairly involved process because it relies on the internal structures of FAT, but it is doable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top