Kill (statement)

Syntax Kill filespec$
Description Deletes all files matching filespec$.
Comments The filespec$ argument can include wildcards, such as * and ? . The * character matches any sequence of zero or more characters, whereas the ? character matches any single character. Multiple * 's and ? 's can appear within the expression to form complex searching patterns. The following table shows some examples.
This Pattern Matches these Files Doesn't match these Files
*S*.TXT SAMPLE.TXT GOOSE.TXT SAMS.TXT SAMPLE SAMPLE.DAT
C*T.TXT CAT.TXT CAP.TXT ACATS.TXT
C*T CAT CAT.DOC CAP.TXT
C?T CAT CUT CAT.TXT CAPIT CT
* (All files)
Example This example looks to see whether file test1.dat exists. If it does not, then it creates both test1.dat and test2.dat. The existence of the files is tested again; if they exist, a message is generated, and then they are deleted. The final test looks to see whether they are still there and displays the result.
Sub Main()
  If Not FileExists("test1.dat") Then
    Open "test1.dat" For Output As #1
    Open "test2.dat" For Output As #2
    Close
  End If
  If FileExists ("test1.dat") Then
    MsgBox "File test1.dat exists."
    Kill "test?.dat"
  End If
  If FileExists ("test1.dat") Then
    MsgBox "File test1.dat still exists."
  Else
    MsgBox "test?.dat successfully deleted."
  End If
End Sub
See Also Name (statement).