Introduction
As a professional programmer, you often have to rename lots of files. While in potential the 'move' command from cmd could do the same, it often ends up in a mess.
Therefore I wrote a simple tool using the Boost libraries regex and filesystem, in which a user supplied directory is scanned and files are renamed by using regex_replace. Note that regex syntax is powerful and complex and therefore I added the possibility to test first the supplied format string.
Simple Use
For a complete overview of boost::regex_replace, please refer to http://www.boost.org/. A simple use was e.g. that a MP3 compressor created '01) Bla.mp3' from my CD's, while I preferred to store them like 'Artist - Bla.mp3'. Feeding '\d{2}\)' as regular expression (without quotes) will instruct the regex engine to search for two numbers followed by a ')'. This match can be replaced by the artists' name.
Code
The code is a simple MFC dialog with two extra classes:
KFrnDirectoryScanner - Thin wrapper around boost::filesystem
KFrnMoveFile - Function object which does the actual renaming
The only caveat is that you better first take a snapshot of the content of the directory, before you end up in recursively calling a just renamed file.
Build
The code is built with Visual Studio 2003. Of course, it is absolutely necessary that you have Boost (version 1.33) and also the DLLs of the above mentioned libraries (see documentation of Boost or my other article 'Building boost libraries for Visual Studio').
Room for Improvement
Probably it would be nice to also have:
- a browse button
- combobox which keeps its history
History
- 9th September, 2005: Initial post