Kill Function

Deletes files from a disk.

The My feature gives you greater productivity and performance in file I/O operations than Kill. For more information, see My.Computer.FileSystem Object.

Public Sub Kill(ByVal PathName As String)


Required. String expression that specifies one or more file names to be deleted. PathName can include the directory or folder, and the drive.

Exception type

Error number




Target file(s) open.



Target file(s) not found.


Permission denied (Visual Basic)

Permission denied.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

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

Security Note   In order to execute, the Kill function requires Read and PathDiscovery flags of FileIOPermission to be granted to the executing code. For more information, see SecurityException, and Code Access Permissions

This example uses the Kill function 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.

This function is not supported.

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Community Additions