To delete a file, files, or one or more subdirectories.
Kill filename$
KillFile filename$
DeleteFile filename$
Kill [Yes | Prompt | Undo | NoUndo | Silent | Files , ] filename$
KillFile [Yes | Prompt | Undo | NoUndo | Silent | Files , ] filename$
DeleteFile [Yes | Prompt | Undo | NoUndo | Silent | Files , ] filename$
filename$ | : sexp; path name |
All three commands perform similar tasks and, in fact, KillFile and DeleteFile are synonymous; the only difference between them and Kill is that, without keywords, Kill permanently deletes a file whereas the others (plus Kill with keywords) send the deleted file to the Recycle Bin.
In their basic form - e.g. KillFile filename$ - these commands delete the specified file; where no path is specified, the file is searched for in the current directory. If the specified file is not found, an error is displayed.
The commands can also be used with the following keywords of which Prompt is the default for all, Undo for KillFile and DeleteFile and NoUndo for Kill:
Yes | Disable confirmation dialog box. |
Prompt | Inquiry before deleting (default). |
Undo | Don't permanently delete file (default for KillFile and DeleteFile). |
NoUndo | The files are deleted irretrievable (default for Kill). |
Silent | Deletes the file without feedback. |
Files | Only files will be deleted, no directories |
You can use the standard wildcard characters to designate more than one file for deletion - "*" to signify any text and "?" to signify any letter; NOTE the wildcard to delete all files is "*", not "*.*".
In addition, these commands can be used to delete one or more subdirectories: for instance, KillFile Files "C:\temp\*" deletes all files in the folder temp but not any subdirectory; KillFile "C:\temp\*" deletes everything.
Local path$ = "C:\TEST.TXT"
Open path$ for Output As # 1 : Close # 1
If Exist(path$) Then KillFile Silent Files path$
Leading commas in front of the file name are ignored, so...
KillFile Undo, Files, Prompt, , , , "c:\temp\*"
...is read as...
KillFile Undo, Files, Prompt "c:\temp\*"
Without keywords, Kill uses the DeleteFile() API, hence the file is permanently deleted; all other operations use the Shell function SHFileOperation – FO_DELETE.
{Created by Sjouke Hamstra; Last updated: 15/07/2020 by James Gaite}