troubleshooting Question

VBScript - Rename Folder

Avatar of G_M
G_MFlag for Australia asked on
VB ScriptWindows 7
9 Comments1 Solution1500 ViewsLast Modified:
Hey guys,

Something so simple seems so hard. I am trying to create a script that will rename a folder to "foldername#" where # is the next backup number. This is to make way for a download of the original folder from a server share.

This is what I have, it isn't working for me.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objNet = CreateObject("WScript.Network")
Set objShell = CreateObject("Wscript.Shell")

strQueryPath = "C:\Users\" & strUserName & "\AppData\Local\Lotus\Notes\Data\"
strQueryFile = "Names.nsf"

'======================================================================================================================================== 
'==== Execution Code ==================================================================================================================== 
'======================================================================================================================================== 

If objFSO.FileExists(strQueryPath & strQueryFile) Then
			WScript.Echo "File Exists"
			intBackup = 1
			Do Until objFSO.FolderExists(Mid(strQueryPath, 1, Len(strQueryPath) - 1) & intBackup & "\") = False
				intBackup = intBackup + 1
			Loop
			
			RenameFolder Mid(strQueryPath, 1, Len(strQueryPath) - 1), Mid(strQueryPath, 1, Len(strQueryPath) - 1) & intBackup

End If

'======================================================================================================================================== 
'===== Functions ======================================================================================================================== 
'======================================================================================================================================== 

Sub RenameFolder(strRenameFrom, strRenameTo)

	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colFolders = objWMIService.ExecQuery ("Select * from Win32_Directory where name = '" & strRenameFrom & "'")
	For Each objFolder in colFolders
		errResults = objFolder.Rename(strRenameFrom & strRenameTo)
		Wscript.Echo errResults
	Next

End Sub

Hope someone can help.
Cheers
G_M
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros