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)

Parameters

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

Exceptions

Exception type

Error number

Condition

IOException

55

Target file(s) open.

FileNotFoundException

53

Target file(s) not found.

SecurityException

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.

Remarks

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

Example

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.
Kill("*.TXT")

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace: Microsoft.VisualBasic

**Module:**FileSystem

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

See Also

Reference

RmDir Function

IOException

FileNotFoundException