os.remove()

Type Function
Library os.*
Return value String and Boolean
Revision 2017.3060
Keywords remove, delete, file
See also system.pathForFile()
os.rename()
io.*

Overview

Deletes a file or directory and returns two possible values:

Gotchas

You can only remove files in the DocumentsDirectory, ApplicationSupportDirectory and TemporaryDirectory. Files in the ResourceDirectory are read-only.

Syntax

os.remove( file )
file (required)

String. String specifying the name of the file or directory to remove.

Example

local destDir = system.DocumentsDirectory  -- Location where the file is stored
local result, reason = os.remove( system.pathForFile( "apple.txt", destDir ) )
 
if result then
   print( "File removed" )
else
   print( "File does not exist", reason )  --> File does not exist    apple.txt: No such file or directory
end