So an upgrade gone wrong at my current client site (no I was not doing the upgrade!) caused about 30 file names to be renamed into a 8.3 format. This little incident brought operations to a halt in almost every branch! No pressure for the consultant, right!
VBS script to the rescue. Just create a input (text) file which has the bad file name, the delimiter of your choice, and the correct file name. It looks like this (with “#” as my delimiter):
badname1.txt#goodname1.txt badname2.txt#goodname2.txt badname3.txt#goodname3.txt etc....
Place this script in the same folder as the input file, change the Path variable to the path containing the files, then run the script.
Const ForReading = 1
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.OpenTextFile(".\name_changes.txt", ForReading)
var1 = f1.ReadAll
var2 = Split(var1, vbcrlf)
path = "C:\Test"
For i = 0 To UBound(var2)
badName = left(var2(i), instr(1, var2(i), "#", 1) -1)
goodName = right(var2(i), instrrev(var2(i), "#", -1) -1)
Set filA = fso.GetFile(path & "\" & badName)
filA.name = goodName
Next
msgbox "All Done!"
By the way, when I showed this script to my son his reply was, “well, that’s not that impressive…”
hmmmm…

