Search and Rename..

menor59

Well-known Member
Joined
Oct 3, 2008
Messages
574
Office Version
  1. 2021
Platform
  1. Windows
So i wrote a VBS script that searches a folder for titles with the word "The" at the beginning...

for example...

The Last Star Fighter
The Day the earth stood still
Gone with the wind
etc etc..

heres the code..

Code:
Const OverwriteExisting = True
 Dim File, Folder, StrF, StrT
 Dim Fso         : Set Fso = CreateObject("Scripting.FileSystemObject")
'/-> Set The Folder Path
  Set Folder = Fso.GetFolder(Fso.GetParentFolderName(WScript.ScriptFullName))
'/-> Object For Collection
  Set File = Folder.Files 
   For Each StrF In File 
'/-> DDRM-filename1.doc Change This DDRM To Match What You Want To Filter
        If InStr(StrF.Name,"The ") Then 
         StrT = Replace(StrF.Path, "The ", "") & ", The"
         Fso.CopyFile(StrF.Path), (StrT),OverwriteExisting
         Fso.DeleteFile(StrF.Path),True  
        End If 
   Next


The Code should rename the titles as follows...
Last Star Fighter, The
Day the earth stood still, The
Gone with the wind

But when i run the VBS i get the following...

Last Star Fighter.mp4, The
Day the earth stood still.mp4, The
Gone with the wind

What am I doing Wrong please?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top