Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming close to 4 million file

Status
Not open for further replies.
Apr 11, 2003
105
US
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

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
 
What is the problem? Are you running out of stack space because of the recursion?
 
The script will not run. When i do run i get Windows Script Host.
The script name
Line: 18
Char: 1
Error: 0x8004103a
Code: 8004103a
Source: Null


Thanks for your help.
 
And what about this ?
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\work")

Sub ShowSubFolders(Folder)
For Each objFile In Folder.Files
If Right(objFile.Name, 2) = ".1" Then
objFile.Name = Left(objFile.Name, Len(objFile.Name)-1) & "doc"
End If
Next
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Name
ShowSubFolders Subfolder
Next
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you, that worked, One last question.
How do i make this script not echo the changes to each foldername?
 
Get rid of the WScript.Echo line.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top