DanClark86
MIS
Hello all, I have a problem where I need to rename 4,000,000 (give or take a few thousand) files in 5000 directories.
Now with the help of the Microsoft website I was able to create a scrip that will change all of the files in a given directory, but the scrip has to be executed from that directory. What I really need is to be able to execute the script and have it drill down to the directory and fine every file that ends in a .1 and change it to a .Doc file
The directories are set up like this
1023
1
file1.1
file2.1
2
file1.1
file2.1
1024
1
file1.1
and so on
Now with the help of the Microsoft website I was able to create a scrip that will change all of the files in a given directory, but the scrip has to be executed from that directory. What I really need is to be able to execute the script and have it drill down to the directory and fine every file that ends in a .1 and change it to a .Doc file
The directories are set up like this
1023
1
file1.1
file2.1
2
file1.1
file2.1
1024
1
file1.1
and so on
Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\work")
Sub ShowSubFolders(Folder)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name=Folder.Path} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In colFileList
If objFile.Extension = "1" Then
strNewName = objFile.Drive & objFile.Path & _
objFile.FileName & "." & "doc"
errResult = objFile.Rename(strNewName)
End If
Next
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Name
ShowSubFolders Subfolder
Next
End Sub