I put this up on my other more work oriented blog, but thought I would share it here too.
In a previous post I explained how to batch rename files using a little DOS, Excel and Notepad. Now I have found a quicker way to accomplish this task. I searched for a vbScript and found this example. This was a great start, I just wanted to make it a little easier for the non-dos friendly users and get it away from the command line. So here is my modified script.
Dim StdIn: Set StdIn = WScript.StdIn
Dim StdOut: Set StdOut = WScript
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim FilesRenamed: FilesRenamed = 0
Dim FilesSkipped: FilesSkipped = 0
dim path
dim olds
dim news
dim ext1
dim ext2
Main
set fso = nothing
Sub Main
'get the parameter list
path=InputBox("Specify Path Of Files To Rename","Enter path")
olds=InputBox("Enter String To Replace","String To Replace")
news=InputBox("Enter New String","New String")
ext1=InputBox("Enter Original Extension","Old Extension","pdf")
ext2=InputBox("Enter New Extension","New Extension", "pdf")
dim CurrentFolder: Set CurrentFolder = fso.GetFolder(path)
ProcessFolder CurrentFolder , olds, news, ext1,ext2
StdOut.Echo "Files renamed :" & FilesRenamed
StdOut.Echo "Files Skipped :" & FilesSkipped
End Sub
Sub ProcessFolder (ByVal folder, ByVal oldTag, ByVal newTag, ByVal extOld, ByVal extNew)
Dim Files: Set Files = folder.Files
Dim File
For Each File In Files
If inStr(1,File.Name,oldTag) > 0 Then
if (extOld <> "" and extNew <> "") then
StdOut.Echo Replace(Replace(File.Path,oldTag,newTag),extOld,extNew)
File.Move Replace(Replace(File.Path,oldTag,newTag),extOld,extNew)
else
StdOut.Echo Replace(File.Path,oldTag,newTag)
File.Move Replace(File.Path,oldTag,newTag)
end if
FilesRenamed = FilesRenamed + 1
Else
FilesSkipped = FilesSkipped + 1
End If
Next
End Sub
I then created a bat file to run the script.
All the end user has to do is double click the bat file and fill in the required information in dialog boxes.
Watch the video below to see it in action
In a previous post I explained how to batch rename files using a little DOS, Excel and Notepad. Now I have found a quicker way to accomplish this task. I searched for a vbScript and found this example. This was a great start, I just wanted to make it a little easier for the non-dos friendly users and get it away from the command line. So here is my modified script.
Option Explicit
Dim StdIn: Set StdIn = WScript.StdIn
Dim StdOut: Set StdOut = WScript
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim FilesRenamed: FilesRenamed = 0
Dim FilesSkipped: FilesSkipped = 0
dim path
dim olds
dim news
dim ext1
dim ext2
Main
set fso = nothing
Sub Main
'get the parameter list
path=InputBox("Specify Path Of Files To Rename","Enter path")
olds=InputBox("Enter String To Replace","String To Replace")
news=InputBox("Enter New String","New String")
ext1=InputBox("Enter Original Extension","Old Extension","pdf")
ext2=InputBox("Enter New Extension","New Extension", "pdf")
dim CurrentFolder: Set CurrentFolder = fso.GetFolder(path)
ProcessFolder CurrentFolder , olds, news, ext1,ext2
StdOut.Echo "Files renamed :" & FilesRenamed
StdOut.Echo "Files Skipped :" & FilesSkipped
End Sub
Sub ProcessFolder (ByVal folder, ByVal oldTag, ByVal newTag, ByVal extOld, ByVal extNew)
Dim Files: Set Files = folder.Files
Dim File
For Each File In Files
If inStr(1,File.Name,oldTag) > 0 Then
if (extOld <> "" and extNew <> "") then
StdOut.Echo Replace(Replace(File.Path,oldTag,newTag),extOld,extNew)
File.Move Replace(Replace(File.Path,oldTag,newTag),extOld,extNew)
else
StdOut.Echo Replace(File.Path,oldTag,newTag)
File.Move Replace(File.Path,oldTag,newTag)
end if
FilesRenamed = FilesRenamed + 1
Else
FilesSkipped = FilesSkipped + 1
End If
Next
End Sub
I then created a bat file to run the script.
cscript renameFiles.vbs
All the end user has to do is double click the bat file and fill in the required information in dialog boxes.
Watch the video below to see it in action
Comments
Post a Comment