I want my files names in real numerical order so 1,2,3,10,12. However it is currently putting them in order like so: 1,10,12,2,3
Input:
files = FileNames["*"]
SortBy [files, N]
Output:
{"10", "1007680", "1007690", "1007700", "1007710", "1007720", \
"1007730", "1007740", "1032540", "1032550", "1032560", "1032570", \
"1032580", "1032590", "1032600", "1032610", "11250", "11260", \
"11280", "11300", "134110", "134120", "134130", "134140", "134150", \
"20", "30", "301720", "301730", "301740", "301750", "301760", \
"38560", "38570", "38580", "38590", "38600", "40", "50", "60", \
"662830", "662840", "662850", "662860", "662870", "662880"}
There must be a simple way to do this that i have missed!
My main goal is that I want mathematica to do a set of operations on each file and plot the results in order of the file name. E.g. so that I can see a change from file 1 to file 1000000.
So my thinking is that I want the list to be like this:
{"10", "20", "30", "40", "50", "60", "3200", "5600", "10000" ...}
Then Mathematica will process and plot the files in the correct order.
SortBy[a, ToExpression]would do it. – Chris Degnen Feb 13 '16 at 16:513) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Feb 13 '16 at 16:54