文件模块新增两个删除文件的方法

This commit is contained in:
MrZ626
2021-05-28 01:23:37 +08:00
parent 6ef7db7ddf
commit c25f2f7cb6

View File

@@ -57,4 +57,32 @@ function FILE.save(data,name,mode)
LOG.print(debug.traceback(),'error')
end
end
function FILE.clear(path)
if fs.getRealDirectory(path)~=SAVEDIR or fs.getInfo(path).type~='directory'then return end
for _,name in next,fs.getDirectoryItems(path)do
name=path.."/"..name
if fs.getRealDirectory(name)==SAVEDIR then
local t=fs.getInfo(name).type
if t=='file'then
fs.remove(name)
end
end
end
end
function FILE.clear_s(path)
if path~=""and(fs.getRealDirectory(path)~=SAVEDIR or fs.getInfo(path).type~='directory')then return end
for _,name in next,fs.getDirectoryItems(path)do
name=path.."/"..name
if fs.getRealDirectory(name)==SAVEDIR then
local t=fs.getInfo(name).type
if t=='file'then
fs.remove(name)
elseif t=='directory'then
FILE.clear_s(name)
fs.remove(name)
end
end
end
fs.remove(path)
end
return FILE