我是电晕的新手,想在我的应用程序中添加一个功能,在按下后退按钮时,用户存储的所有数据都会从文档目录中删除。总之我想知道有没有办法清空文档目录?
问问题
1879 次
2 回答
1
使用它来删除 /documents 目录中的所有文件
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
于 2013-01-24T07:18:16.007 回答
1
是的,你会为此使用 LFS(Lua 文件系统)模块。看:
http://www.coronalabs.com/blog/2012/05/08/luafilesystem-lfs-tutorial/
于 2013-01-23T22:36:18.850 回答