KILL Statement ---------------------------------------------------------------------------- Action Deletes files from a disk. Syntax KILL filespec$ Remarks The KILL statement is similar to the DOS ERASE or DEL command. KILL is used for all types of disk files. program files, random-access data files, and sequential data files. The filespec$ is a string expression that can contain a path and question marks (?) or asterisks (*) used as DOS wildcards. A question mark matches any single character in the filename or extension. An asterisk matches one or more characters. KILL deletes files only. To delete directories, use the DOS RMDIR command or BASIC RMDIR statement. Using KILL to delete a file that is currently open produces an error message that reads File already open. Warning Be extremely careful when using wildcards with KILL. You can delete files unintentionally with the wildcard characters. See Also FILES, RMDIR Examples The first example uses wildcard characters with KILL. It will not work properly unless the specified files are found. KILL "DATA1?.DAT" ' Kills any file with a six-character ' base name starting with DATA1 and ' also with the extension .DAT. KILL "DATA1.*"' Kills any file with the base name ' DATA1 and any extension. KILL "\GREG\*.DAT"' Kills any file with the extension ' .DAT in a subdirectory called GREG. The following example deletes the file specified on the command line. DEFINT A-Z CLS ' Clear screen. ON ERROR GOTO Errorhandle' Set up error handling. FileName$ = COMMAND$ ' Get filename. KILL FileName$ PRINT FileName$ " deleted" END Errorhandle. Number = ERR IF Number = 53 THEN PRINT "Couldn't delete " FileName$ ; PRINT "; file does not exist in current directory" ELSE PRINT "Unrecoverable error.";Number ON ERROR GOTO 0 ' ON ERROR GOTO zero aborts program. END IF RESUME NEXT