VBScript – Rename the Extension of all the Files in the Current Directory

Here is another odd problem I had to tackle and which VBScripting was up to the task of easily handling.

I had the need of changing the extension of all the files in a folder from *.wdseml to *.eml. If you only have 1 or two files, a manual solution is feasible, but in this instance I needed to change the extension on thousands of files, so an automated solution was needed. Below is the script that I put together for the job. It could easily be modified to prompt the user to make it more versatile…

'*******************************************************************************
'Author:	Daniel Pineault / CARDA Consultants Inc.
'Purpose:	This script will, without any prompts to the end-user, rename
'		all file extension specified to whatever new file extension is 
'		specified of all the files meeting the criteria in the same
'		folder as the vbscript
'Revision:	2012-01-31   Initial Release
'*******************************************************************************

sVBSPath = Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName) _
		     - (Len(WScript.ScriptName) + 1)))
with createobject("wscript.shell")
   .currentdirectory = sVBSPath
   .run "%comspec% /c ren *.wdseml *.eml", 0, true
end with