1

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
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?

Alex
  • 166
  • 13
  • 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*](https://stackoverflow.com/q/20530996). – Kamil Maciorowski May 03 '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 03 '18 at 19:48
  • 1
    Note: [XY problem](https://meta.stackexchange.com/a/66378/355310). – Kamil Maciorowski May 03 '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](https://blogs.msdn.microsoft.com/oldnewthing/20140304-00/?p=1603). – Kamil Maciorowski May 03 '18 at 20:13
  • @KamilMaciorowski I recognized it as an XY problem right away; but, in this case, whatever the successful solution is, the way to check its success is, by running the `dir` function, and verify that the files are in the right order. So I don't see a downside of asking it like this. – Alex May 03 '18 at 20:24
  • @KamilMaciorowski Degragmenting the USB player made the "old" method work, thanks! Feel free to post this as an answer. – Alex May 03 '18 at 20:26
  • I pass, so you can answer your own question without stealing any credit. – Kamil Maciorowski May 03 '18 at 20:30
  • I plan to do it eventually if noone else does; but in the meanwhile, I would like to say that ultimately, what happened was, that the display order was correlated to the order on disk. So my general strategy ended up, write a large file so the system would find some free contiguous space; then, erase that file, and in its place write my files in alphabetical order. Since the system is already positioned to reclaim the large file, it doesn't look for smaller gaps that can fit some of the smaller files, and hence all files end up in alphabetical order. – Alex May 04 '18 at 02:45
  • See [this comment](https://superuser.com/q/1321460/432690#comment1969830_1321460). – Kamil Maciorowski May 11 '18 at 03:19
  • 2
    Possible duplicate of [How to reorder the files of a FAT32 file system?](https://superuser.com/questions/376577/how-to-reorder-the-files-of-a-fat32-file-system) – phuclv Mar 17 '19 at 09:10

0 Answers0