Questions? Comments? Email articles-photorenaming [at] tucuxi [dot] org
Abstract
Renaming 4-digit photos to allow for more than 10,000 images without duplicated filenames, by adding a prefix.
Introduction
As might be expected, I tend to shoot a fair number of photographs from time to time, and only recently have I found that the auto-numbering from my camera crossed the rollover point. Most digital cameras have a three-character prefix (IMG, CRW etc.), followed by an underscore and a four-digit number. This limits users to having 10,000 photos without any filename duplication, and I recently crossed that mark.
I like to give each photo a unique identifier, and as I only shoot with a single camera, this built-in numbering is fine. Well, it was fine, until I hit the 10,000 image mark. After a bit of thought as to what would be the better method - introducing a 5th digit, or starting the numbering from scratch, I wrote a script not dissimilar to the one available from this page. The script in question searched for all images in a certain directory, and prepended a 0 to the sequence number.
As can be expected from any developer, I took the initial concept, and over-engineered it. The updated and semi-cleaned script is available from the link at the top of this page, and can be used to rename your photos.
Compatibility
The script's knowledge of valid prefixes and extensions has been altered in an
ad-hoc fashion as new extensions and prefixes arise, so it may need a bit of
modification before it's suitable for your needs. At the moment, it's been
tested with a Canon DSLR, with only the CRW_ prefix. IMG_ images will not
be touched, nor will DSC_; all the requisite changes are in the regular expression
that contains ^(crw).
License
The code is released under the BSD license; if you like it, or find it useful, drop me an email.
Help page
Image Renamer v0.01 (c) 2006 Ben Stewart
This script will process the files within the current directory, or the
directories specified on the command line. Files of the form abc_0000.*
will be renamed to include a sequence number prepended to the four-digit
image number, so that crw_0123.jpg will turn into crw_10123.jpg.
This script was created mainly to facilitate the expansion of photo
collections beyond 10,000 images, as most digital cameras only number
images with a four-digit index.
Usage:
./rename.php [options] [dir1 dir2 ...]
Options:
--help Display this screen
-d Perform the rename instead of just simulating.
--doit
-v List all the renames performed
--verbose
--prefix=xx Set the photo prefix. This string will be prepended to
the photo index. It is suggested that this is an integer,
however any string may be specified.
-0 to -9 Set the photo prefix. These options are shorthand for
--prefix=0..9.
--min=983 Set the minimum photo index to 983. Default is 0000.
--max=1833 Set the maximum photo index to 1833. Default is 9999.
Both the --min and --max options take an integer
argument, representing the range of photo indexes that
will be given the prefix. These are provided to limit
the transition to a certain time period of photo - for
example, if you have 4000 to 9999 requiring a prefix of
0, and 0000 to 2300 requiring a prefix of 1, you would
execute the script twice:
./rename.php -0 --min=4000
./rename.php -1 --max=2300