Name

File.Move Method

Syntax

                  oFileObj.Move destination
oFileObj

Use: Required

Data Subtype: File object

Any object variable returning a File object.

destination

Use: Required

Data Subtype: 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 oFileObj must not be open or an error occurs.

  • Wildcard characters can’t be used in Destination.

  • Destination can be either an absolute or a relative path.

Programming Tips & 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 containing oFileObj is automatically updated, the moved folder is being removed, and the collection count, ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.