This used to be really easy in the old OS's.

dir /o:n >> list.txt
for %a in (`list.txt`) do copy %a ..\ordered

And voila, there was the list of files in the other folder, created in the sorted order. This way, when I do a regular dir ..\ordered, the files would show up in the order of their filenames.

This no longer works in the new systems. When I execute the above, the dir ..\ordered ends up showing the files in the same order as they were in the original folder.

I tried copying onto another drive. The files were copied one at a time using a script, in the alphabetical order; I even put pauses between the copies, to make sure some sort of caching didn't make them write to disk out of order. However, when I do a dir command, they again show up out of order-- this time, in a different order than they were in the original directory. However, copying to the same drive multiple times seems to result in the same order on that drive.

I checked to see what attributes the sort order on dir was based on, to see if I could touch those attributes up. I checked the following attributes

Date Accessed
Date Created
Date Last Saved
Date Modified

Sorting by these attributes never yielded the same order as the dir command does.

How to override this behavior, and get a custom order when running dir?

| improve this question | | | | |
  • In many Linux shells one can define an alias to inject a desired parameter (like /o:n, -o n or whatever); or a function. Well, in Linux one can override ls with custom script or program. I don't know how fortunate you are in Windows in this subject. Maybe you will find a solution here: Aliases in Windows command prompt. – Kamil Maciorowski May 3 '18 at 19:39
  • No, I can definitely override the list order on Windows. The problem is that, I am then copying these files to an MP3 player, and the order they show up there is precisely the order that they show up in the un-overridden dir function. The MP3 player is whose order I cannot override. – Alex May 3 '18 at 19:48
  • 1
    Note: XY problem. – Kamil Maciorowski May 3 '18 at 20:08
  • 1
    What filesystem? Could it be "it used to be really easy" because you used to work with defragmented filesystem(s)? Read this. – Kamil Maciorowski May 3 '18 at 20:13
  • 2
    Possible duplicate of How to reorder the files of a FAT32 file system? – phuclv Mar 17 '19 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.