25 Latest Videos

Filenames and sorting

Posted on Friday, February 08, 2008:: 922 Views



So you renamed all your files with a sequence number, and uploaded them to a gallery... but they are not displaying in the order you want them to... why is that?

Computers look at numbers differently than we do - they see only the first digit and use that to sort by first, then they sort by the next digit and so on. So when a computer sees the following numbers:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,18,20

It will sort them like this:

1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9

which appears out of order to us, but realizing the computer is merely sorting by the first digit it sees, it makes sense.

So how do you solve this? Very easily... all you need to do is make sure that all numbers have the same number of digits - adding leading zero's in when needed. So in the above example all numbers need to have 2 digits, which would be this:

01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20

So if you have filenames that go from 1 to 1250, all numbers need to have 4 digits, like this:

0001,0002,0003.... 0099,0100,0101,0102.... 0999,1000,1001,1002

The main time you will see this is when posting images to a web gallery. Modern Operating Systems like Windows XP and Mac OSX are smart enough to display numbers the way we expect to see them, but webservers still sort based on the first digit. Thankfully almost all renaming utilities give you the option to specify the number of digits each number will have, which takes care of the problem.



<< Back to Articles Index


Related Articles:

Anatomy of the Histogram
Posted on Monday, June 22, 2009 :: 2543 Views

Images and Their Histograms - Examples
Posted on Tuesday, July 22, 2008 :: 2142 Views

Color Channels and Color Theory
Posted on Thursday, May 22, 2008 :: 3526 Views

Understanding Resolution Part 1
Posted on Monday, January 28, 2008 :: 1071 Views

Understanding Resolution Part 2-Resampling
Posted on Sunday, January 27, 2008 :: 1083 Views