© Matti Mattila, CPFA, CISA, CIA

5. File Renaming Macro (NAMM)

Next Item Previous menu
There are cases when one wants to rename lots of files. E.g. I myself have digital still camera (Sony DSC-P71) that gives snapshots names such as 'DSC00001.JPG', 'DSC00002.JPG', 'DSC00003.JPG', etc. Those file names do not tell anything about the images. I have renamed them using functionality of windows (right-click on mouse; selecting 'rename' and so on). However, renaming large number of files indvidually takes much time.
In order to resolve the renaming problem I first resorted to bat files. I created a file name file (e.g. 'zz.txt') using DOS command 'dir *.* > zz.txt', and edited it in notepad (removing unnecessary text, inserting 'REN' and new file names). Renaming took still much time. Finally I made an IDEA macro that
- creates list of files to be renamed ('zz.txt') using DOS command 'dir *.* > zz.txt'.
- imports certain data of 'zz.txt' to IDEA using its 'Import a print report file' method. Because structure of 'zz.txt' varies between Windows versions (e.g. Windows 98 vs. Windows XP) there is no universal mask [1].
- creates elements of bat file for changing file names ('zz.bat'). User is asked for file name prefix; special characters are removed from it automatically. Prefix is followed by '_' and running number ('001', '002', etc). Each file name gets its running number based on the age of the file compared to age of other files.
- exports elements of bat file as 'zz.bat' to directory of files to be renamed.
- opens 'zz.bat' in Notepad and tells the user to remove quotation marks (e.g. with 'replace') from it. One can make other changes as well. Save the file after that.
Please, note! The actual renaming takes place when you click 'zz.bat' in the directory of the files to be renamed.
To download demo version of NAMM.ISS (NMM.ise) click here. For sake of simplicity the macro needs to access 'a:' drive to use 'zz.txt' and 'zz.msk', and to create 'zz.imd'. So, you should unzip 'nmm.zip' to discette and keep it in drive 'a:' when running the macro.

[1] Two masks ('zz.msk' and 'zz98.msk') are included in the same downloadable zip file where 'rmm' macro exists. The macro uses 'zz.msk' as default. If you wish to use 'zz98.msk' in stead just replace "a:\zz.msk" with "a:\zz98.msk" on the line 40 of 'nmm'.
See also functionality of 'ReNam' Excel macro in renaming files!