Reputation: 1619
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?
Upvotes: 1
Views: 1921
Reputation: 1619
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
Upvotes: 1
Reputation: 3063
Yes, you would use the LFS (Lua File System) module for that. See:
http://www.coronalabs.com/blog/2012/05/08/luafilesystem-lfs-tutorial/
Upvotes: 1