We can move one or more folders from one location (source location) to another location (destination location). Moving a folder from one location to another location is equivalent to Cut the folder from one location and Pasting it in another location. The function MoveFolder can be used to do this. The same function can be also used for renaming folders. The syntax of the 'MoveFolder' function is given below.
MoveFolder source folder, destination
The argument 'source folder' is the source folder name with the complete path. This argument can contain wild card characters ('*' or '?') also for moving multiple folders.
The argument 'destination' should be complete path to the destination location. It must end with a backward slash (\) or new folder name. If the destination is ending with a backslash(\), then it is assumed that the destination folder exists and the folder will be moved to this location with the same name. If the destination is ending with a new folder name, then the folder will be moved to the destination with the new folder name. This argument cannot have wild card characters ('*' or '?')
Note: To rename an existing folder make sure that the source folder location and destination location are the same; and the destination folder should not end with a backslash
Following are some examples to move and rename folders in vbscript.
Set FS = CreateObject("Scripting.FileSystemObject")
FS.MoveFolder "C:\Source Folder", "C:\Destination Folder\"
WScript.Echo("Folder Moved")
Set FS = CreateObject("Scripting.FileSystemObject")
FS.MoveFolder "C:\Folder-*", "C:\Destination Folder\"
WScript.Echo("All Folders like Folder-1, Folder-2 etc are Moved")
Set FS = CreateObject("Scripting.FileSystemObject")
FS.MoveFolder "C:\Source Folder", "C:\Renamed Folder"
WScript.Echo("Folder Renamed")