Starting with AGG version 0.2.3, AGG includes a Batch Renamer tool, which is useful for renaming a large bunch of files according to some rule.
The simplest example is making the filenames lowercase, but it can be used for more elaborate stuff as well.
Example of the renaming dialog
Rename files in: Choose the directory to be processed
Include subfolders: Process subfolders recursively if ticked
Files to rename: You can select all files, or process only files matching some wildcard
Case insensitive: Matching for file names is by default case sensitive, i.e. a "*.jpg" wildcard will not match .JPG or .Jpg files, only .jpg. If you don't want this, click on the Case Insensitive tick
The wildcards can consist of the usual DOS patterns like "*.jpg", "*.*", "img*.*", "pict_02??.jpg" etc. The asterisk matches any number of characters (no restrictions). The question sign matches only one character. You can also include the UNIX-y construct "[chars]" - this matches any of the characters in the square brackets. E.g. "[asg]" matches the characters 'a', 's' and 'g', but nothing else. You can also include ranges, like in "[a-z]", "[A-Za-Z0-9]" (the former matches any small latin letter; the latter matches any alphanumeric character). You can also mix all these styles. For example, the wildcard "[A-Zx][1-5][0-9][0-9][a-zA-Z0-9][a-zPQM0-9]*.jpg" matches all files which: "Begin with a capital letter or small 'x'; continue with a digit from 1 to 5; continue with two digits; continue with an alphanumeric; continue with a character, that is either 'P', 'M', 'Q', or small latin, or a digit; continue with any characters; and finish with .jpg"
If you need to match plain square brackets in the file names, escape them with a backslash.
The custom renaming allows you to apply some common renaming scheme to a number of similarly-named files. You have to specify a "rename rule", which is a template string denoting the basic format of the resulting filenames, and containing some special characters, which are to-be replaced by some parts of the input filenames. Here's how it works:
For each input file, AGG extracts four parts of its name - the prefix, the number, the suffix and the extension. The prefix is the beginning of the name before any digits. The number is the block of digits after the prefix. The suffix is everything after the first block of digits, until the final dot, exclusive. The extension is the rest, but without the dot. For example, in the filename DSC_98123_small.pro01.jpg, the prefix is "DSC_", the number is "98123", the suffix is "_small.pro01", and the extension is "jpg". In some cases, some of these substring might be empty, e.g. in "IMG_0005.jpg", the suffix is empty. In "annie_portrait.jpg" there is neither a number, nor a suffix.
The rename rule consists of normal characters, which will be used verbatim in the output filenames, and also contain the following special tokens:
|%a||the input filename (usually equivallent to %p%n%s.%e)|
(e.g., %1,n %2,n ... etc.)
|The first, second, ... etc. number (from AGG 0.2.5 onward)|
(e.g., %1,t %2,t ... etc.)
|The first, second, ... etc. non-number (from AGG 0.2.5 onward)|
|UP(...)||uppercased version of the string inside the parentheses|
|LOW(...)||lowercased version of the string inside the parentheses|
|CAP(...)||capitalized (first character is uppercase, others are lowercase) version of the string inside the parentheses|
|REV(...)||reverse of the string inside the parentheses|
|PAD(char,number,...)||a version of the string used as the third "argument", but padded with copies of the character char from the left, until the length of the string is number characters. If the given string is already longer, nothing happens.|
|SLICE(i,j,...)||Pythonic slice: Slices the string used as the third "argument" and returns only
the characters staring from i (inclusive) to j (exclusive). E.g., SLICE(4,7,abcdefgh) will return "efg"
(counting starts from zero). You can also skip some of the parameters (to assume the beginning or the end of the stirng),
or you can use negative parameters, which are counted relative to the end of the string. E.g., SLICE(-3,-1,%p) will get you
the two characters before the last character of the prefix.|
From AGG 0.2.5 onward.
So, for each file you want to rename, AGG looks at the renaming rule and does the substitution of special characters (e.g. it replaces %p
with the prefix of the current file).
You can also get substrings of the %-ish tokens, by placing a number between the "%" and the symbol (if you use the %1,n-like formats, place those numbers after the comma). For example "%5p" gets only the first five characters of the prefix, while "%-5p" gets only the last five characters of the prefix. In case the string is shorter than the given number, the whole string is returned. Please note that %5p is equivallent to SLICE(,5,%p) and %-5p is equivallent to SLICE(-5,,%p)
See the following examples for further clarifications:
|Rename rule||What it does|
|CAP(%a)||Uppercase the first character of the filename, lowercase the rest|
|example_UP(%a)||Uppercase the whole filename and prefix it with `example_'|
|%p%n%s.LOW(%e)||Make file extension lowercase|
|Image_PAD(0,5,%n).%e||Rename files like IMG3.JPG, IMG21.JPG to Image_00003.JPG, Image_00021.JPG|
|%3p%-2n.LOW(%2e)||Take the first three characters of the preifix, last two of the number, skip the suffix and lowercase the first two characters of the extension|
|LOW(REV(%s)REV(%n)REV(%p)).%e||Lowercase the reversed filename, keeping the original extension|
|LOW(%p)_no_PAD(0,10,%n)UP(%s).LOW(%e)||Place the lowercased prefix, append `_no_', append the number, extended with zeros from the left to length 10, append the uppercased suffix, and lowercase the extension|
|%pPAD(0,6,REV(%-2n))%s%s.UP(%e)||Place the prefix unmodified, get the last two digits of the number, reverse them and pad zeros to length six. Then, append two copies of the suffix; a dot and uppercased extension.|
|%p%n_%2,-2n%3,n%4,n.%e||Consider the file name img_0552-2010-06-11.jpg. Now we have multiple "numbers" inside the file name. %n (first number) caputres 0552. %2,n gets 2010, %3,n is 06 and %4,n is 11. We want to turn the date into 6-digit short format (YYMMDD). So we take the year (%2,n) and modify it to fetch only the last two digits (%2,-2n). To this we append the month and day, unmodified. So we finally get "img_0552_100611.jpg". If we wanted output names like DD.MM.YY.jpg, we would have used "%4,n.%3,n.%2,-2n.%e"|
|%p%n_SLICE(-2,,%2,n)%3,n%4,n.%e||Same as the previous example, but using a slice.|
Suppose you have two folders with two sets of photos, each named like "IMG_0001.jpg", "IMG_0002.jpg", etc. And you want to merge them in one folder.
Each set has less than 100 photos. Simply copying the images from the one folder to the other will overwrite one of the sets. So here's our renaming plan: We will keep
the first set of photos untouched, and will rename the second set to IMG_0101.jpg, IMG_0102.jpg... etc.
To do that, select the second folder, select to include All files, and for the renaming rule use "%p01%-2n.%e".
Even better: suppose the first set was shot by Laura, and the second by Viktor. You can rename the first set with the rule "Laura_%n.%e" and the second with "Viktor_%n.%e", clearly marking the photographer of each file.
Did it ever happen to you to "overflow" your camera's image number counter? Like shooting a few images "IMG_9995.JPG", ..., "IMG_9999.JPG",
"IMG_0000.JPG", "IMG_0001.jpg",...? This leaves your folder badly sorted - since the IMG_0000.jpg will be first alphabetically, though not chronologically.
OK, let's fix this. We will add a fifth digit in front of the other four, which will be '0' in front of '999?' images and '1' in front of '000?' images.
Step 1: Select only files matching "IMG_9???.JPG" and use the rename rule "%p0%n.%e"
Step 2: After the previous rename is done, select only files matching "IMG_0???.JPG" and apply the rule "%p1%n.%e"