FileSystemObject.DeleteFile Method (VB6) |
Named Arguments
Yes
Syntax
oFileSysObj.DeleteFile FileSpec [, Force]
oFileSysObj
Use: Required
Data Type: FileSystemObject object
Any object variable returning a FileSystemObject object.
FileSpec
Use: Required
Data Type: String
The name and path of the file or files to delete.
Force
Use: Optional
Data Type: Boolean
If set to True, the read-only flag on a file is ignored and the file deleted.
Description
Permanently removes a given file or files.
Rules at a Glance
FileSpec can contain wildcard characters as the final path component.
FileSpec can be a relative or absolute path.
If any of the files specified for deletion are open, the method fails with a Permission Denied error.
The default setting for Force is False.
If the specified file or files can't be found, the method fails.
If only a filename is used in FileSpec, the application's current drive and directory is assumed.
Programming Tips and Gotchas
If an error occurs while deleting more than one file, the DeleteFile method exits immediately, thereby leaving the rest of the files undeleted. There is also no roll-back facility to undo deletions prior to the error.
If the user has adequate rights, the source or destination can be a network path or share name. For example:
DeleteFile "\\NTSERV1\RootTest\myFile.doc"
DeleteFile permanently deletes files; it doesn't move them to the Recycle Bin.
See Also
- Kill Statement
Get VB & VBA in a Nutshell: The Language 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.