This is my folder structure.
/home/files/encounters 9-22-11-0.jpg .. /home/files/encounters 9-22-11-[n].jpg
puts Dir.glob("/home/files/*.jpg")[0]
When i execute the above code, it displayed the sixth file (index 5 => /home/files/encounters 9-22-11-5.jpg), but actually i need the output as first file(index 0 => /home/files/encounters 9-22-11-0.jpg)
How can i sort the files as user defined sorting order?. like
When i tried..
..[0] => /home/files/encounters 9-22-11-5.jpg
..[1] => /home/files/encounters 9-22-11-21.jpg
..[2] => /home/files/encounters 9-22-11-39.jpg
But, I need
..[0] => /home/files/encounters 9-22-11-0.jpg
..[1] => /home/files/encounters 9-22-11-1.jpg
..[2] => /home/files/encounters 9-22-11-2.jpg
Additional information, sorting is also not working.
f = Dir.glob("/home/files/*.jpg").sort
f[0] => /home/files/encounters 9-22-11-0.jpg
f[0] => /home/files/encounters 9-22-11-1.jpg
f[0] => /home/files/encounters 9-22-11-10.jpg
f[0] => /home/files/encounters 9-22-11-11.jpg
Would work if you had a format like
11-09-22-05.jpg
instead of9-22-11-5.jpg
. You could try to sort them as a number instead.But as it seems you have month-day-year-number I guess that the correct way to sort is a bit more complicated than that.
It works by reformatting
9-22-11-5.jpg
to an array containing[11, 9, 22, 5]
and then sorts by that instead.