vbscript saves the day

I had some mp3 tracks of an audiobook in different folders but not in succession
Disk 1 - > 01.Track.mp3, 02.Track.mp3
Disk 2 - > 01.Track.mp3, 02.Track.mp3, 03.Trackmp3
Disk 3 - > 01.Track.mp3, 02.Track.mp3

I wanted to put them all into the same directory but to do this I had to rename them so that end result would be like

Disk 1 - 01.Track.mp3, 02.Track.mp3
Disk 2 - 03.Track.mp3, 04.Track.mp3, 05.Track.mp3
Disk 3 - 06.Track.mp3, 07.Track.mp3

I googled for file-renamers but did not see one that was fit for this purpose so, I wrote a simple vbscript:

set oFSO=CreateObject("Scripting.FileSystemObject")
set oFolder=oFSO.GetFolder(".")

Dim sUsage
sUsage = "Usage: cscript rename.vbs NumberToAdd"

If ((Wscript.Arguments.Count = 0) or (Not IsNumeric(iAdd))) Then
Wscript.Echo (sUsage)
End If

Dim iAdd: iAdd = CInt(Wscript.Arguments(0))

For Each oFile in oFolder.Files
If IsNumeric(sFirstTwo) Then
sFirstTwo = sFirstTwo + iAdd
sNewName = sFirstTwo & sRest
Wscript.Echo (sFile & "-->" & sNewName)
oFile.Move (sNewName)
End If

C:\Disk 9>cscript rename.vbs 159
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

01. Track 1.mp3-->160. Track 1.mp3
02. Track 2.mp3-->161. Track 2.mp3
03. Track 3.mp3-->162. Track 3.mp3
04. Track 4.mp3-->163. Track 4.mp3
05. Track 5.mp3-->164. Track 5.mp3
06. Track 6.mp3-->165. Track 6.mp3
07. Track 7.mp3-->166. Track 7.mp3
08. Track 8.mp3-->167. Track 8.mp3
09. Track 9.mp3-->168. Track 9.mp3
10. Track 10.mp3-->169. Track 10.mp3
11. Track 11.mp3-->170. Track 11.mp3
12. Track 12.mp3-->171. Track 12.mp3
13. Track 13.mp3-->172. Track 13.mp3
14. Track 14.mp3-->173. Track 14.mp3
15. Track 15.mp3-->174. Track 15.mp3
16. Track 16.mp3-->175. Track 16.mp3
17. Track 17.mp3-->176. Track 17.mp3
18. Track 18.mp3-->177. Track 18.mp3
19. Track 19.mp3-->178. Track 19.mp3
20. Track 20.mp3-->179. Track 20.mp3
21. Track 21.mp3-->180. Track 21.mp3
22. Track 22.mp3-->181. Track 22.mp3
23. Track 23.mp3-->182. Track 23.mp3
24. Track 24.mp3-->183. Track 24.mp3
25. Track 25.mp3-->184. Track 25.mp3

Overly simplistic, but did the trick :) Copy the code sniplet into the directory and give it a name eg. rename.vbs to run it.

Oh, BTW, I would strongly suggest that you take a look at a free utility named Ant Renamer by Antoine Potten who also wrote another fantastic free application called Ant Movie Catalog

I actually talked to Antoine today and told him the story. He mentioned that I could have in fact used 'Enumaration function' in the Ant Renamer to add sequential numbers in front of the filenames and then delete the old numbers using "Characters Deletion" function. Nice!

No comments: