Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

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