View recent posts | Search forum topics
I want to add a functionality in my app that if user press back button without saving his/her data, all saved files in documents directory get deleted.. Now I dont know how to completely flush this directory. Can anybody help me here?
Have a look at these links
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("Error removing file: "..file..":"..errorMsg);
it is working ...
Although its not an issue but just for the curiosity that this loop not only delete the files in documents directory but also delete the complete folder `/documents` ...
Is it possible that the directory become empty but not deleted
On relaunching the project, it is there,so not an issue
Ooops! That's what I get for writing code in a post without testing... really sorry for that.
I forgot that it returned the system files "." and ".." Ouch!
Anyway the code above has been modified to test for directories now and should only remove all files...
well this too deleting \documents directory.
I dont know why as check is there but still..!!