Name
File.Move Method
Syntax
oFileObj.Movedestination
oFileObjUse: Required
Data Type: File object
A File object.
destinationUse: Required
Data Type: String
The path to the location where the file is to be moved.
Description
Moves a file from one folder to another.
Rules at a Glance
The file represented by
oFileObjmust not be open or an error occurs.Wildcard characters can’t be used in
Destination.Destinationcan be either an absolute or a relative path.
Programming Tips and Gotchas
If a fatal system error occurs during the execution of this method (like a power failure), the worst that can happen is that the file is copied to the destination but not removed from the source. There are no rollback capabilities built into the File.Move method; however, because the copy part of this two-stage process is executed first, the file can’t be lost.
If a folder or a file by the same name already exists in
destination, the method generates runtime error 58, “File exists.” To prevent this, you can use the FileSystemObject’s FileExists and GetAbsolutePath methods prior to calling the Move method.Unlike the FileSystemObject’s MoveFile method, which accepts wildcard characters in the path parameter and can therefore move multiple files, the Move method moves only the single file represented by
oFileObj.As a result of the Move method, the Files collection object originally containing
oFileObjis automatically updated, the file is removed from it, and the collection count is reduced by one. You shouldn’t try ...
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