1

I am new to corona and want to add a functionality in my app that on pressing back button, all data stored by the user get deleted from the documents directory. In short I want to know is there a way to empty documents directory?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
aneela
  • 1,457
  • 3
  • 24
  • 45

2 Answers2

1

Yes, you would use the LFS (Lua File System) module for that. See:

http://www.coronalabs.com/blog/2012/05/08/luafilesystem-lfs-tutorial/

Rob Miracle
  • 3,053
  • 1
  • 13
  • 12
1

Use this to delete all the files in /documents directory

 local lfs = require "lfs";

local doc_dir = system.DocumentsDirectory;
local doc_path = system.pathForFile("", doc_dir);
local resultOK, errorMsg;

for file in lfs.dir(doc_path) do
local theFile = system.pathForFile(file, doc_dir);

if (lfs.attributes(theFile, "mode") ~= "directory") then
  resultOK, errorMsg = os.remove(theFile);

  if (resultOK) then
     print(file.." removed");
  else
     print("Error removing file: "..file..":"..errorMsg);
  end
  end
  end
aneela
  • 1,457
  • 3
  • 24
  • 45