Name
FileSystemObject.MoveFile Method
Syntax
oFileSysObj.MoveFilesource,destination
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
sourceUse: Required
Data Type: String
The path to the file or files to be moved.
destinationUse: Required
Data Type: String
The path to the location where the file or files are to be moved.
Description
Moves a file from one folder to another.
Rules at a Glance
If
sourcecontains wildcard characters or ifdestinationends in a path separator,destinationis interpreted as a path; otherwise, its last component is interpreted as a filename.If the destination file exists, an error occurs.
sourcecan contain wildcard characters, but only in its last component. This allows multiple files to be moved.destinationcan’t contain wildcard characters.Both
sourceanddestinationcan be either absolute or relative paths.Both
sourceanddestinationcan be network paths or share names.
Programming Tips and Gotchas
MoveFile resolves both arguments before beginning the operation.
Any single file move operation is atomic; that is, any file removed from
sourceis copied todestination. However, if an error occurs while multiple files are being moved, the execution of the function terminates, but files already moved aren’t moved back to their previous folder. If a fatal system error occurs during the execution of this method (like a power failure), the worst that can happen is that the affected file is copied to the destination but not removed from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access