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.Delete Method

Syntax

                  oFileObj.Delete [Force]
oFileObj

Use: Required

Data Type: File object

A File object.

Force

Use: Optional

Data Type: Boolean

If set to True, ignores the file’s read-only flag (if it’s on), and deletes the file.

Description

Removes the current file.

Rules at a Glance

  • The Delete method deletes a file permanently; it does not move it to the Recycle Bin.

  • If the file is open, the method fails with a “Permission Denied” error.

  • The default setting for Force is False.

  • If Force is set to False, and the file is read-only, the method will fail.

Programming Tips and Gotchas

  • Unlike the FileSystemObject object’s DeleteFile method, which accepts wildcard characters in the path parameter and can therefore delete multiple files, the Delete method deletes only the single file represented by oFileObj.

  • As a result of the Delete method, the Files collection object containing oFileObj is automatically updated, the deleted file is removed from the collection, and the collection count is reduced by one. You shouldn’t try to access the deleted file object again; you should set oFileObj to Nothing.

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