Sorting File paths
Posted: Wed Oct 05, 2016 12:36 am
Hey guys, i've been scratching my head over this one. Lets say I have an array containing some file paths:
Folder/1.txt
Folder/23.txt
Folder/6.txt
Folder/Piano.txt
Folder/Wave01.txt
Folder/Wave02.txt
Zebra/1.txt
Zebra/76.txt
Zebra/9.txt
Now when ruby gets these paths it looks different from windows. Ruby thinks 23 comes after 1 because it starts with a 2, but they should be numerically higher, like this:
Folder/1.txt
Folder/6.txt
Folder/23.txt
Folder/Piano.txt
Folder/Wave01.txt
Folder/Wave02.txt
Zebra/1.txt
Zebra/9.txt
Zebra/76.txt
Is there a way to sory them by using the .sort_by function or something else?
Thank you!
Folder/1.txt
Folder/23.txt
Folder/6.txt
Folder/Piano.txt
Folder/Wave01.txt
Folder/Wave02.txt
Zebra/1.txt
Zebra/76.txt
Zebra/9.txt
Now when ruby gets these paths it looks different from windows. Ruby thinks 23 comes after 1 because it starts with a 2, but they should be numerically higher, like this:
Folder/1.txt
Folder/6.txt
Folder/23.txt
Folder/Piano.txt
Folder/Wave01.txt
Folder/Wave02.txt
Zebra/1.txt
Zebra/9.txt
Zebra/76.txt
Is there a way to sory them by using the .sort_by function or something else?
Thank you!