© Matti Mattila, CPFA, CISA, CIA

6. File Renaming Macro, 2nd version (NAM2)

Previous Item Next item Previous menu
The macro introduced here is an improved version of the macro described on the previous page.
For various reasons you might want to rename files based on the alphabethical order of their existing names in stead of age of files. Still, you might want to keep the latter mentioned option available.
Operating system has the best information about ages of files. So I keep on using DOS command 'dir *.* > zz.txt'. The simplest way to create a file where file names of interest are in alphabethical order is DOS functionality, e.g. command combination 'dir *.*|sort/+40>zz.txt' in Windows 2000 [1].
The macro works as follows.
Picture 1
Picture 2
- Soon after starting the macro you are shown the dialog in picture 1.
- By default the macro renames files based on the alphabetical order of the existing file names. If this is what you want you need do nothing. If you want the files to be renamed based on their age select option "According to age of files".
- To continue execution of the macro click the button bearing text 'Select any file to be renamed': the browser starts; select any file to be renamed.
- To stop the macro, click the button bearing text 'End Script'.
- Next, you are asked to submit prefix for the files to be renamed (File name prefix:'). In picture 2 file names will start with prefix 'Helsinki_2004_November_'. Special characters are allowed in the prefix. The prefix is followed by a running number. In the case of the picture the first of the running numbers will be '101'.
- To continue execution of the macro click the button bearing text 'OK'. You can stop the macro by clicking the button bearing text 'Cancel'.
- In other respects the macro works like NAMM.iss. However, I have made it easier to use macro on hard disk. As a default macro uses drive 'a:\' determined by command 'Path2="a:\"' (on line 10). If you want to locate files needed in running the macro e.g. in a folder 'd:\macros\' just change the command respectively ('Path2="d:\macros\"') and put the macro and the files it needs ('zz1.bat'; 'zz2.bat', 'zz.msk') in that folder.
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 NAM2.ISS ('NM2.ise') click here. The zip file contains batch and mask files for Windows 2000 (2k.zip) and Windows XP (XP.zip) users.

[1] The number 40 indicates the column position where the file name starts in 'zz.txt'.
See also functionality of 'ReNam' Excel macro in renaming files!