File Renaming Utility
Location - Utilities
NOTE - Use at Your Own Risk. File Renaming CANNOT be undone!
Renaming files can be a long, laborious process. Most of the time, the file renaming that you're looking to do for a set involves taking files that match a specific pattern, and renaming them accordingly.
Say you have the following files:
pics_001/full/chelsea_001.jpg
pics_001/full/morri_002.jpg
pics_001/full/steph_003.jpg
pics_001/full/lara_004.jpg
pics_001/full/tanya_005.jpg
And are looking to rename them to:
pics_001/full/001.jpg
pics_001/full/002.jpg
pics_001/full/003.jpg
pics_001/full/004.jpg
pics_001/full/005.jpg
Typically this would be a manual process. This is where the file renamer comes in. It takes an input pattern, and creates an output pattern:
Source Pattern:
pics_001\/full\/(\S+)_(\d+)\.jpg
Destination Pattern:
pics_001/full/$2.jpg
If you put this into the renaming tool and hit "preview", you will see the desired text in the renaming tool. Now, let's dissect what's going on.
Source Pattern:
Full Line: pics_001\/full\/(\S+)_(\d+)\.jpg
pics_001 : This is the folder name. It's just text.
\/ : When doing a regular expression search, a forward slash needs to be escaped by putting a backslash in front of it.
\. : When doing a regular expression search, a period normally matches any character. For a period to mean a period, put a backslash in front of it.
(\S+) : This matches one or more characters that isn't whitespace (a space, a tab, a return line). To match just one non-whitespace character, use (\S)
(\d+) : This matches one or more decimal number (0-9). If you notice that both of these have a plus in front of them, that's because the plus sign means "one or more"
jpg : This is the end of the pattern. It's just text.
Destination Pattern:
Full Line: pics_001/full/$2.jpg
$2 : The only thing special going on here is the $2 sign. A dollar sign with a number after it refers to the Nth instance of () within the source line.
: So, for instance, if your destination pattern had been $1.jpg, you would end up having your files named chelsea.jpg, morri.jpg, steph.jpg, etc.
A full list of special characters that are used in PHP Regular Expressions are available here:
http://us3.php.net/manual/en/reference.pcre.pattern.syntax.php
A more extensive regular expression tutorial is available here:
http://www.regular-expressions.info/tutorial.html
Unique constants
----------------
If you specify these within the Destination Pattern, the following will happen:
#number#: Renames files in order, so that 0238.jpg, 0382.jpg, 0412.jpg, 0521.jpg will become 0001.jpg, 0002.jpg, 0003.jpg, 0004.jpg.
: This is used if you have a lot of different files named inconsistently.
#folder#: Includes name of the folder in destination pattern
: So, if the folder name you're doing changes in is called ba_arron, the destination pattern of #folder#-#number#.jpg will create ba_arron-001.jpg, ba_arron-002.jpg, etc...
#remove#: Instead of renaming the content, remove a matching pattern from the folder