MoveFolder Method
Move one or more folders from one location to another.
object.MoveFolder source, destination
Parameters
Object
Required. The name of FileSystemObject.
Source
Required. The path of the folder to be moved.SourceThe parameter string can only contain wildcards in the last component of the path.
Destination
Required. Specifies the path to move the folder to the target location.DestinationParameters cannot contain wildcards.
Description
IfSourceContains wildcards orDestinationEnd with path separator (\), it is assumedDestinationSpecify an existing folder to move matching files to the folder. Otherwise, assumeDestinationIs the target folder to be created. In either case, when moving a single folder, the following three situations may occur:
- IfDestinationIf the folder does not exist, move the folder. This is usually the case.
- IfDestinationIf it is an existing file, an error occurs.
- IfDestinationIs a directory, an error occurs.
IfSourceIf a wildcard is used but the folder does not match, an error occurs.MoveFolderMethod stops when the first error occurs. This method does not cancel any changes made before the error occurs.
The following example illustrates how to useMoveFolderMethod:
Sub MoveAFolder(Drivespec) Dim fso Set fso = CreateObject("Scripting.FileSystemObject") fso.MoveFolder Drivespec, "c:\windows\desktop\"End Sub
Key PointsThis method allows moving folders between two volumes only when supported by the operating system.