1

tl;dr I cannot replicate sort order used by dir command in Windows 10, neither within File Explorer nor Total Commander. I have tried to change sort order based on many different columns and still nothing. Thus, I am wondering how files listed by dir command are ordered by default? And how can I change it?


I have noticed that my MP3 player plays music in a "weird" order. To investigate this I have:

  • mounted SD card under my Windows 10,
  • run cmd as an administrator,
  • navigated to SD card root,
  • executed dir command.

I have received following output:

 Volume in drive D has no label.
 Volume Serial Number is 36BA-963E

 Directory of D:\

05.06.2018  23:00       159ÿ280ÿ594 02. Stream.mp3
15.10.2019  20:18       144ÿ000ÿ738 05. Campfire.mp3
11.02.2020  23:32       134ÿ040ÿ469 07. Piano Soft.mp3
11.02.2020  17:32       153ÿ195ÿ986 10. Flutes.mp3
16.09.2019  05:09       171ÿ600ÿ882 11. Tibetan.mp3
11.02.2020  08:13       115ÿ326ÿ973 13. Train.mp3
20.10.2018  22:16       159ÿ280ÿ281 01. Birds.mp3
05.06.2018  23:00       161ÿ086ÿ282 03. Sea.mp3
05.06.2018  23:00       161ÿ247ÿ510 04. Rain.mp3
05.06.2018  23:00       159ÿ280ÿ596 06. Cave.mp3
11.12.2019  17:57       131ÿ792ÿ464 12. Meditation.mp3
10.02.2020  19:42       142ÿ827ÿ986 08. Piano Water.mp3
10.02.2020  21:57       159ÿ780ÿ933 09. Jazz.mp3
              14 File(s)  1ÿ952ÿ741ÿ728 bytes
               0 Dir(s)   5ÿ819ÿ006ÿ976 bytes free

As you can see -- files are not sorted by filename. By changing sort order through many columns I was not able to replicate above sort order. I tried:

  • file name,
  • file extension,
  • file size,
  • date created,
  • date modified and
  • date last saved.

All for nothing.

Can someone guide me, what is the default sort order as used by dir command?

And even more important -- how to change it (since my MP3 player plays files in exactly the same "weird" order)? By "change it" I mean, which property of each file (i.e. maybe some date) I should modify in order to have sort order reported by dir command as close to alphabetical one as possible?

1 Answer 1

2

It's the filesystem order – in file managers it would be called "no sort order whatsoever".

For FAT filesystems, a directory is stored as a simple list of the file entries in series. Whenever a file is deleted, its slot is marked as empty. Whenever a new file is added, it occupies the first slot that's free, which might be at the end or somewhere in the middle. (That's slightly simplified – for example, in reality, "long" file names occupy multiple slots – but it should get the point across.)

(This is not exactly the same as ordering by creation date, as it's determined based on when the file was placed in that specific folder, not when it was created overall.)

This means that one way of sorting the files is to create a new directory, then move files into it one by one in the exact order that you want. Many players work the same way as yours, so there already exist tools for achieving that:


Meanwhile, for the NTFS filesystem, directory entries are stored in a B+tree, so they're always in a well-defined order – if I remember correctly NTFS orders the entries based on the UTF-16 form of the file name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .