从系统中删除所有文件.电晕中的文档目录



我是 corona 的新手,想在我的应用程序中添加一项功能,即按下返回按钮后,用户存储的所有数据都会从文档目录中删除。简而言之,我想知道有没有办法清空文档目录?

是的,您可以使用 LFS(Lua 文件系统)模块。 看:

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

使用它删除/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

最新更新