How to sort numbers according to the first digit?

0 like 0 dislike
20 views
Hello! There are pictures. Need to sort them
Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 30.04.2018 23:23 0 1.jpg -a--- 30.04.2018 23:34 0 1.png -a--- 30.04.2018 23:40 0 10.jpg -a--- 30.04.2018 23:39 0 10.png -a--- 30.04.2018 23:39 0 100.png -a--- 30.04.2018 23:23 0 2.jpg -a--- 30.04.2018 23:34 0 2.png -a--- 30.04.2018 23:39 0 22.png -a--- 30.04.2018 23:40 0 23.jpg

I tried to sort by dir 5 | sort {[int]$_.name}, but not out. How to sort ascending/descending (upper list)?
by | 20 views

3 Answers

0 like 0 dislike
1, 1, 2, 2, 10, 10, 22, 23, 100
Interesting, but it's the way files are sorted
in Explorer
5ae84651f363e995944001.png
by
0 like 0 dislike
just, in this particular case, you need to remove from name all what is not a number:
dir c:\\test\\pstest | sort {[int]($_.name-replace "\\..*")}

the same result will be if you change the regular season like this:
dir c:\\test\\pstest | sort {[int]($_.name-replace "\\D")}

when you change the file naming scheme, the regular season, too, will need to change.

and to sort in reverse order sort-object is the key-descending. just add it to the end of the row.
by
0 like 0 dislike
Obviously, it is not necessary to call files of sorts in numeric order only explorer on Windows. Fill the number with zeros.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Jun 4, 2019 by Fajamaja
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
33,949 users