PSTree icon indicating copy to clipboard operation
PSTree copied to clipboard

Sort by ascending values

Open jlnrrg opened this issue 2 years ago • 3 comments

I noticed that the default output is sorted descending. It has been a long time since I last worked with PS, so I am not aware how to resort the tree later on. If you know I would be happy for advice, otherwise I would propose a sorting flag, or to make the default sort ascending, as that would mimik the default windows explorer sorting behaviour.

Cmd I've run: Get-PSTree -Directory

jlnrrg avatar Mar 14 '23 11:03 jlnrrg

Hi @jlnrrg thanks for opening this issue, I'm aware of it but I'm not sure if there is a way around it. This is a consequence of using a Stack<T> instead of doing it with recursion. Older versions of this function were using recursion but it was changed for efficiency. If you find out a way please let me know and I'll try to implement it.

santisq avatar Mar 14 '23 13:03 santisq

Now that you've rewritten in C#, shouldn't it be easy to sort it ascending by default now? I'm guessing here but wondered if you thought about it. The link to the stack<T> code is broken now by the way.

krzydoug avatar Apr 18 '24 05:04 krzydoug

Now that you've rewritten in C#, shouldn't it be easy to sort it ascending by default now? I'm guessing here but wondered if you thought about it. The link to the stack code is broken now by the way.

Hi @krzydoug, it's not as easy as it may seem, each sub tree needs to be sorted individually (all files within a folder) and then each parent tree (all folders). I don't see a way to make it happen easily and also, even then, making it work would have a high performance hit but if you want to give it a go, the method that traverses the folders is here: https://github.com/santisq/PSTree/blob/main/src/PSTree/Commands/GetPSTreeCommand.cs#L143-L249

santisq avatar Apr 18 '24 14:04 santisq