SoFunction
Updated on 2025-04-13

VBS Tutorial: Method - DeleteFile Method

DeleteFile method

Delete the specified file.

object.DeleteFile filespec[, force]

parameter

object

Required option. Should be the name of FileSystemObject.

filespec

Required option. The file name to be deleted.filespecWildcards can be included in the last component of the path.

force

Optional. Boolean value. If you want to delete a read-only file, the value isTrue; otherwiseFalse(default).

illustrate

If no matching file is found, an error will appear.DeleteFileThe method stops when the first error occurs. This method does not undo any changes made before the error occurs.

The following example shows how to use itDeleteFilemethod:

Sub DeleteAFile(filespec)  Dim fso  Set fso = CreateObject("")  (filespec)End Sub