vbscript recursive rename file extensions

May 20, 2010 at 14:58:14
Specs: Windows XP
I need to recursively change the file extensions of a large number of files. I have read through a number of different potential scripts and have found this particular post to be helpful: http://www.computing.net/answers/pr...

But I can't get it to work the way I would need. Since it is not renaming extensions but is renaming the actual filename.

The script below renames the extensions for the higher level directory but I am trying to get it to read through the entire directory tree for a particular file and change the file extensions. But I can't see to be able to modify the script from the above post in a manner that would run the script that I have posted below recursively.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Test'} Where " _
& "ResultClass = CIM_DataFile")

For Each objFile In colFiles
strExtension = objFile.Extension
strExtension = Replace(strExtension, "ini", "ixi")
strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & strExtension
errResult = objFile.Rename(strNewName)


See More: vbscript recursive rename file extensions

Report •

May 20, 2010 at 20:07:05
@echo off & setlocal
cd \work
for /f "tokens=*" %%a in ('dir /b /ad') do (
pushd %%a
call :aa

(set /p=--------<nul & cd
dir /b *.ex1 2>nul
:ren *.ex1 *.ex2
dir /b *.ex2 2>nul)>> c:\work\foo.log
::--------- end
this just generates a "what if" testfile.
all subdirectories will be accessed, and once the colon
is removed from the "ren" statement, all extensions
should be changed.

Report •

May 21, 2010 at 11:12:25
I truly appreciate the batch file -- it does rename extensions nicely. But I need to do this in VBScript because the program can't call a batch file....but it can call a vbscript.

Report •

Related Solutions

Ask Question