Skip to main content

Redoing Renaming Files

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.

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

Popular posts from this blog

Name The People

I was asked by a co-worker to create some Revit families from CAD blocks. They are 2D plan representations of people. I asked the requester if she wanted them named any certain way because this is what I saw.

A Weekend in the VA Mountains

This past weekend we took a trip to the mountains of Virginia. It is an area we have visited before with the Boy Scout troop, but this time we went without the scouts. I have been riding consistently again for nearly a year after I bought a new to me cyclocross bike. You can read more about that here . After more than 2,800 miles on that bike since last June, it needed some more work. The headset was pretty much shot and would not be repaired in time for our planned trip to Virginia. So Gina suggested that I get a new bike. I ended up getting a Giant Revolt Advanced 2 from Giant Wake Forest . We arrived at our rental house very early Saturday morning. 1:30am in fact. We found a place to stay that was literally steps away from The Virginia Creeper Trail . Saturday was to be a day we went hiking at Grayson Highlands State Park . We met Gina's co-workers at the park just after 10:00 am and started our hike. We have camped at this park before with the Boy Scouts but have never ...

Record Store Day 2019 Roundup

Well, it's been nearly a year since my last blog post . Fittingly that was about my then new turntable. Ever since I received that wonderful gift I have been increasing my collection of vinyl records. This year when the list of records was released for Record Store Day I became very excited. There were several releases which I was looking forward to purchasing. Bingo Hand Job - Live at The Borderline 1991 Green Day - Live at Woodstock 1994 The Minus 5 - Stroke Manor Rush - Hemispheres (40th-anniversary picture disc) Various Artists - Music From and Inspired by the motion picture South Park: Bigger, Longer & Uncut Violent Femmes - Hallowed Ground Each of the records is a special edition released specifically for Record Store Day 2019 and are limited in quantity. This is what makes this day so special to someone like me.  I started my Saturday, April 13, 2019, at 4:00am. I arrived at the first store of the day, Schoolkids Records , there was already a sub...