O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

File.Move Method

Syntax

                  oFileObj.Move destination
oFileObj

Use: Required

Data Type: File object

A File object.

destination

Use: 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 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 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 oFileObj is automatically updated, the file is removed from it, and the collection count is reduced by one. You shouldn’t try ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required