Monday, May 27, 2019

VBScript rename file names in folder

VBScript code rename files;find and replace file names windows;find and replace file names VBScript;VBScript Find and Replace in File Names










1) Create a file rename_script.vbs and paste the below code. VBScript can be written using Windows Notepad or any other plain text editor.

 Set objFso = CreateObject("Scripting.FileSystemObject")  
 Set Folder = objFSO.GetFolder("C:\Users\MyName\Documents\MyDirectory\")  
 For Each File In Folder.Files  
   sNewFile = File.Name  
   sNewFile = Replace(sNewFile,"find","_")  
 if (sNewFile<>File.Name) then  
   File.Move(File.ParentFolder+"\"+sNewFile)  
 end if  


2) Save the file and double click to execute.

Note: "Swim at your own risk", the code doesn't have extensive error handling. Just be sure to replace the "C:\Users\MyName\Documents\MyDirectory" with the path to your directory.

No comments:

Post a Comment