Blitz3D+ Command Reference

DeleteFile file$

Parameters

file$ - path and name of the file to delete

Description

Deletes a file from disk.

The file is removed permanently - it does not go to the Recycle Bin - so take care, especially when the name comes from a variable. Typical game uses are removing a save slot or cleaning up temporary files.

DeleteFile raises no error if the file does not exist or cannot be removed (for example when it is read-only or still open). Close any stream you have on the file first, and use FileType to confirm the file is gone if it matters.

See also: CopyFile, DeleteDir, FileType.

Example

; DeleteFile Example
; ------------------

; Create a throwaway file so there is something safe to delete
file=WriteFile("demo_delete_me.txt")
WriteLine file,"This file exists only to be deleted"
CloseFile file
Print "Created demo_delete_me.txt   (FileType = "+FileType("demo_delete_me.txt")+")"

; Delete it - only ever delete files your program owns!
DeleteFile "demo_delete_me.txt"
Print "Deleted demo_delete_me.txt   (FileType = "+FileType("demo_delete_me.txt")+")"

Print ""
Print "FileType 1 = file exists, 0 = gone"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index