Name Mangler 3 includes date-based renaming features outside of Advanced mode; this article will be of interest only to those running Name Mangler 2.
Name Mangler is our user-friendly yet powerful batch file renamer. In this how-to, I’ll show you how to use Name Mangler’s Advanced mode to add date and/or timestamps to your filenames (and how to replace a portion of the filename, all in one pass).
While Advanced mode can be intimidating, the objective of this tutorial is to show you that it may not be as bad as you fear, and that you can do quite a lot with it. To get the most out of this tutorial, I recommend you create a batch of sample files, and follow along in Name Mangler, trying each step as you read.
Name Mangler’s Help file contains an entire section on Advanced mode, covering all the commands available; if you have the display space, opening the Help window alongside the tutorial and Name Mangler could be very useful.
Although date and time information is attached to every file on your Mac, sometimes you might want that information actually in the filename—if you want an easy visual reference as to a file’s creation time, for instance. In Name Mangler’s normal modes, you can’t do anything at all with file date and time stamps. In Advanced mode, though, you can. Advanced mode provides three functions that work with dates and times:
- created – A file’s creation time.
- modified – A file’s modification time.
- now – The current date and time.
To work with these functions, though, you need one additional bit of knowledge: how to format their output. All three of these functions can be formatted using the Unix strftime date/time formatting command. strftime uses a series of specifications, expressed with a percentage sign followed by a single character. These specifications determine which date and/or time fields are displayed, and how they are formatted.
As an example, the string %A %B %e, %Y [%l:%M%p] would display as:
Tuesday March 20, 2012 [11:15am]
You can see all of the options for strftime formatting by typing man strftime in Terminal. However, for easier reading, you can also see the help file online. Take a minute to glance through some of the available configuration options.
Now that you know a bit about strftime formatting, here’s how to use that knowledge to append dates and/or times to your filenames. Consider this typical example, where I have a series of images loaded into Name Mangler:
I want to rename these images so that the creation date is at the start of the filename, and in such a form that the files will be in date order when viewed in alpha order in any Finder window. To do that, I’m going to add the date in the form of YYYY-MM-DD [hh_mm], with the time portion in 24-hour mode, so I won’t need am/pm.
Note that I’m not using colons to separate the time elements, because the colon is a special character in OS X; it’s used to denote paths in certain areas of the OS, so it’s best to stay away from colons in filenames.
To make things more interesting, I’m also going to replace the IMG_ portion of the filename with something a bit more informative, to show just some of what you can do in one pass with Advanced mode renaming.
First, though, I’ll add the creation date and time (via the created function) to the filename. The strftime format that I need for my output is:
%Y-%m-%d [%H_%M]
With the format ready, all I need to do is insert it at the beginning of the filename. To do that, I use another Advanced mode function, concatenate, which will join my date string to the existing filename. I’ll join my time string to the <name.extension> constant, which contains the filename and its extension, if one exists. The code looks like this:
[concatenate
[created
"%Y-%m-%d [%H_%M] "
],
<name.extension>
]
With that code placed in Name Mangler’s Advanced mode pane, you can see the before-and-after affect on my filenames:
That takes care of the first part of my renaming, but I’ve still got IMG_ in there. These photos are of bits of furniture from our home (for an insurance file), so I’d like to have them say Home_ instead of IMG_. To do that, I’ll add the find function into my renaming code:
[concatenate
[created
"%Y-%m-%d [%H_%M] "
],
[find
"IMG_",
<name.extension>,
"Home_"
]
]
The find function is relatively easy to understand: it searches for IMG_ in <name.extension> and replaces it with Home_.
And that’s that:
Once I click the Rename button, I’ll have a set of files named with a leading date and time stamp, making it easy to not only have them sorted by date, but to see that date in any view mode I happen to be using.