A client of mine has a bunch of folders and files that need renaming, so I wrote a quick VBS to iterate through subfolders and move the contents to the correct places as well as rename the folder. To do this, I'm primarily using the objFSO.moveFile oldname, newname command.
Now the problem is this thing works fine on my computer with a few tiny files and a few folders. My client has thousands of these folders and when he runs the script the program will cease up after a few hundred of these folders. The number this stops on varies from machine to machine, so it looks like it's a resource issue that's causing the script to break down. I realize there's no "rename" function in VBS and it renames stuff by calling a move command. Is there some sort of memory leak or some big no-no with this procedure?
Now the problem is this thing works fine on my computer with a few tiny files and a few folders. My client has thousands of these folders and when he runs the script the program will cease up after a few hundred of these folders. The number this stops on varies from machine to machine, so it looks like it's a resource issue that's causing the script to break down. I realize there's no "rename" function in VBS and it renames stuff by calling a move command. Is there some sort of memory leak or some big no-no with this procedure?
Code:
sub movefiles(byVal strFolderPath, byVal newpath, byVal basepath)
Dim objCurrentFolder, colSubfolders, name
dim path
dim oldname
dim newname
dim lastpath
'new counter
dim multipleFiles
dim counter
'verification
If objFSO.FolderExists(strFolderPath) Then
'set necessary current variable things
Set objCurrentFolder = objFSO.GetFolder(strFolderPath)
Set colSubfolders = objCurrentFolder.SubFolders
Set colFiles = objCurrentFolder.Files
multipleFiles = colFiles.count
counter = 1
path = newpath + "\" + objCurrentFolder.name
'iterate through sub folders & change directory path that the shell is currently in.
For Each objFolder in colSubfolders
objShell.CurrentDirectory = objFolder
call movefiles(objFolder.Path, path, basepath)
Next
'copy file
If (multipleFiles > 1) Then
For Each objFile in colFiles
oldname = objFile
newname = basepath & "\" & objCurrentFolder.name & "_" & counter & Right(objFile.name,4)
objFSO.moveFile oldname, newname
counter = counter + 1
Next
else
For Each objFile in colFiles
oldname = objFile
newname = basepath & "\" & objCurrentFolder.name & Right(objFile.name,4)
objFSO.moveFile oldname, newname
Next
end if
end If
End sub
