Kill

Deletes files from a disk.

Syntax: Kill pathname

pathname
required String expression that specifies one or more file names to be deleted. The pathname may include the directory or folder, and the drive.

Kill supports the use of multiple-character (*) and single-character (?) wildcards to specify multiple files.

Note

To delete directories, use the RmDir statement.

Common Errors

Error When
-2147467259 (&H80004005), Unspecified error no file matches pathname, which includes a folder, a folder or drive that does not exist, and a zero-length string
the file, or a file a wildcard matches, is read-only
the file, or a file a wildcard matches, is open
94 (&H5E), Invalid use of Null pathname is Null

Note BETA 1034

When no file matches pathname, which includes a folder, a folder or drive that does not exist, and a zero-length string, VB6 and 64-bit VBA raise error 53 (&H35), File not found, instead.

Note BETA 1034

When the file, or a file a wildcard matches, is read-only, VB6 and 64-bit VBA raise error 75 (&H4B), Path/File access error, instead.

Note BETA 1034

When the file, or a file a wildcard matches, is open, VB6 and 64-bit VBA raise error 55 (&H37), File already open, instead.

Note BETA 1034

When pathname names a hidden or system file, VB6 and 64-bit VBA raise error 53 (&H35), File not found; twinBASIC raises none.

Example

This example uses the Kill statement to delete a file from a disk.

' Assume TESTFILE is a file containing some data.
Kill "TestFile"   ' Delete file.

' Delete all *.TXT files in current directory.
Kill "*.TXT"

See Also