Filenames and Sorting Issues

» Posted on February 8 2008 in Filenames

So you renamed all your files with a sequence number, and uploaded them to a gallery (or sent them to a lab for printing)… 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:


It will sort them like this:


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:


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 printing them at a lab. Modern Operating Systems are smart enough to display numbers the way we expect to see them, but when images are sent to the printer the logic takes over and they may sort improperly if they don’t have the leading zeroes.

Generally when we see this at our lab it is for album prints where the designer numbered them from 1-30 or whatever and forgot the leading zero. If the images are straight from a camera, the camera adds the leading zero and they are correct.

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.

So remember - all files should have the same number of digits in the filename! and you should never see a 1 without a zero or 2 in front of it.