Name
File.Delete Method
Syntax
oFileObj
.Delete [Force
]
-
oFileObj
Use: Required
Data Subtype: File object
Any object variable returning a File object.
-
Force
Use: Optional
Data Subtype: 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
isFalse
.If
Force
is set toFalse
, and the file is read-only, the method will fail.
Programming Tips & 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 setoFileObj
toNothing
.
See Also
FileSystemObject.DeleteFile Method |
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.