Renaming files in style
Once upon a time I wrote about a piece of software of mine, a stack-oriented file renaming tool. I thought this was rather nifty as I have only ever seen the regular-expression-hell approach to renaming files where you have a regular expression that can actually cause grievous bodily harm, you use this to (hopefully) match the parts of the filename that you want to keep (or alter) and then construct your new filename from these components; all in all, a bit like drying yourself off with a vacuum cleaner.
Often you actually want to perform relatively complex tasks on some of these filename components, like "proper" casing a title or looking up a TV episode name from the season number, show name and episode number. In these situations, a stack-oriented approach gives you better flexibility because you can program the behaviour (assuming a reasonable set of basic functions) with something a little more sturdy than regular expressions
After working on my original code a bit more, I found I could leverage these strengths to do a lot of really repetitive work for me, such as renaming TV episodes and so rn was born. You can run an rn script over a given set of filenames and have it work its magic, which is obviously where you can save yourself a lot of time and effort. My pride and joy is my TV episode renaming script, it's process is as follows:
- Split a filename into it's useful parts (series name, season number, episode number) according to a set of regular expressions that match the most common naming conventions.
- Query tvrage.com's "raw data" service with the information we have.
- Rename the file according to the data we get back.