Default file order of "dir" command in Windows console
dir
(without arguments) command always shows files/dirs unsorted, in other words - in same order, as files/dirs are located on disk. NTFS file system "sorts" files/dirs internally (simplifying).
Thought, you may copy files one-by-one to achieve preferred sorting on your player.
The order is "undefined", see below. But this is an XY problem because there are a lot of tools made for your real sorting purpose
- mp3DirSorter
- YAFS: Yet Another FAT Sorter
- FAT Reader
- FAT-32 Sorter
- FAT Sorter
- Sort MP3 Files On MP3 Player
- https://github.com/maxpat78/FATtools
- https://svnpenn.github.io/rosso/
- How to reorder the files of a FAT32 file system?
According to Microsoft's dir
documentation (emphasis mine)
/o [[:]SortOrder]
: Controls the order in whichdir
sorts and displays directory names and file names. If you omit/o
,dir
displays the names in the order in which they occur in the directory. If you use/o
without specifyingSortOrder
,dir
displays the names of the directories, sorted in alphabetic order, and then displays the names of files, sorted in alphabetic order. The colon (:
) is optional.
The order in which files occur in a directory depends on the file system and how they store file lists in a directory entry:
- In FAT12/16/32 the file allocation table is just a simple linear list and when a new file is created it's simply put in an empty space in the list. Hence depending on the creation and deletion state the list order will vary. That explains why mp3 players often play in the order you copy files to the folder
- In NTFS directory entries are stored in a B-tree structure, so the result will be an almost-sorted list
More on Raymond Chen's blog: What order does the DIR
command arrange files if no sort order is specified?
If you don't specify a sort order, then the
DIR
command lists the files in the order that the files are returned by theFindFirstFile
function.Um, okay, but that just pushes the question to the next level: What order does
FindFirstFile
return files?The order in which
FindFirstFile
returns files in unspecified. It is left to the file system driver to return the files in whatever order it finds most convenient.
You can manually sort the files by moving them to another directory in the order you want
If the storage medium is a FAT-formatted USB thumb drive, then the files will be enumerated in a complex order based on the order in which files are created and deleted and the lengths of their names. But the easy way out is simply to remove all the files from a directory then move file files into the directory in the order you want them enumerated. That way, the first available slot is the one at the end of the directory, so the file entry gets appended.