Delete a file or directory

Verified
Added by iNTERFACEWARE

Use os.remove() to delete a file or directory, only an empty directory can be deleted

Source Code
   -- create and delete a file

   -- create a file
   io.open('MyTempFile', 'w')
   os.fs.stat('MyTempFile')
   
   -- remove (delete) the file
   os.remove('MyTempFile')  
   os.fs.stat('MyTempFile') -- stats no longer available
   
   -- create and delete a directory

   -- create a directory
   os.fs.mkdir('MyTempDir')
   os.fs.stat('MyTempDir')
   
   -- remove (delete) the directory
   os.remove('MyTempDir')  
   os.fs.stat('MyTempDir') -- stats no longer available
Description
Use os.remove() to delete a file or directory, only an empty directory can be deleted
Usage Details

Use os.fs.remove() to delete a file or directory. Directories must be empty before they can be deleted.

How to use the snippet:

  • Paste the desired deletion code into your script