Windows "tree" command sorts randomly

Solution 1:

Tree is a very simple program which loops through all the directories (and if specified the files). It does not do buffering. You can see this because it builds the tree of directories directly on screen (if the output is not redirected). With lots of directories this is slow and output begins right away.

Because tree does not read all the directories at once it can do no sorting. So it is dependent on the filesystem to present the directories in order. If the filesystem does not do this, tree will not be ordered.

If you want an ordered list you will have to go for a utility that can read all the directory and files at once and then present an ordered tree-like view.

Solution 2:

There are two options known by me:

  1. Total Commander and its tree invoked by AltF10. Then you can find the tree nicely sorted in c:\Users\your_username\AppData\Local\GHISLER\ in file treeinfoC.wc. You may need to remove brackets [] then by some editor and its regular expression replace function.
  2. Use console (cmd.exe) command:

    dir /b /s /ad c:\
    

    which can be redirected to a file by:

    dir /b /s /ad c:\ > c:\all_c_drive_folders.txt