调整命令行的del指令

This commit is contained in:
MrZ626
2021-03-16 01:29:45 +08:00
parent 782732278e
commit 5beec7ea38

View File

@@ -282,9 +282,9 @@ end
local function tree(path,name,depth) local function tree(path,name,depth)
local info=love.filesystem.getInfo(path..name) local info=love.filesystem.getInfo(path..name)
if info.type=="file"then if info.type=="file"then
log(string.rep("\t\t",depth)..name) log(("\t\t"):rep(depth)..name)
elseif info.type=="directory"then elseif info.type=="directory"then
log(string.rep("\t\t",depth)..name..">") log(("\t\t"):rep(depth)..name..">")
local L=love.filesystem.getDirectoryItems(path..name) local L=love.filesystem.getDirectoryItems(path..name)
for _,subName in next,L do for _,subName in next,L do
tree(path..name.."/",subName,depth+1) tree(path..name.."/",subName,depth+1)
@@ -302,7 +302,7 @@ function commands.tree()
end end
end end
function commands.del(name) function commands.del(name)
if name then if name~=""then
local info=love.filesystem.getInfo(name) local info=love.filesystem.getInfo(name)
if info then if info then
if info.type=="file"then if info.type=="file"then
@@ -314,18 +314,18 @@ function commands.del(name)
elseif info.type=="directory"then elseif info.type=="directory"then
if #love.filesystem.getDirectoryItems(name)==0 then if #love.filesystem.getDirectoryItems(name)==0 then
if love.filesystem.remove(name)then if love.filesystem.remove(name)then
log({COLOR.Y,"Succesfully deleted"}) log({COLOR.Y,"Succesfully deleted file '"..name.."'"})
else else
log({COLOR.R,"Failed to delete"}) log({COLOR.R,"Failed to delete file '"..name.."'"})
end end
else else
log{COLOR.R,"Directory is not empty"} log{COLOR.R,"Directory '"..name.."' is not empty"}
end end
else else
log("Unkown item type: %s (%s)"):format(name,info.type) log("Unkown item type: %s (%s)"):format(name,info.type)
end end
else else
log{COLOR.R,"No file called "..name} log{COLOR.R,"No file called '"..name.."'"}
end end
else else
log{COLOR.water,"Usage: del [filename]"} log{COLOR.water,"Usage: del [filename]"}