From 5aa483b4452ff0cf2d085e7ab9a293c1f27c95da Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sat, 1 May 2021 19:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=96=B0=E5=A2=9Ere?= =?UTF-8?q?n(=E9=87=8D=E5=91=BD=E5=90=8D)=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/scenes/app_console.lua | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index e68499ba..41d4abc7 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -100,6 +100,15 @@ do--commands.help(arg) "Usage: del -s [dirname]", }, },rm="del", + ren={ + description="Rename a file (in saving directory)", + details={ + "Rename a file (in saving directory)", + {C.lY,"Warning: file name with space is not allowed"}, + "", + "Usage: ren [oldfilename] [newfilename]", + }, + }, cls={ description="Clear the log output.", details={ @@ -239,6 +248,7 @@ do--commands.help(arg) "url", "tree", "del", + "ren", "cls", "rst", "fn", @@ -400,6 +410,37 @@ do--function commands.del(name) end commands.rm=commands.del end +function commands.ren(arg) + --Check arguments + arg=STRING.split(arg," ") + if #arg>2 then + log{C.lY,"Warning: file name with space is not allowed"} + return + elseif #arg<2 then + log{C.aqua,"Usage: ren [oldfilename] [newfilename]"} + return + end + + --Check file exist + local info + info=love.filesystem.getInfo(arg[1]) + if not(info and info.type=='file')then log{C.R,("'%s' is not a file!"):format(arg[1])}return end + info=love.filesystem.getInfo(arg[2]) + if info then log{C.R,("'%s' already exists!"):format(arg[2])}return end + + --Read file + local data,err1=love.filesystem.read('data',arg[1]) + if not data then log{C.R,("Failed to read file '%s': "):format(arg[1],err1 or"Unknown error")}return end + + --Write file + local res,err2=love.filesystem.write(arg[2],data) + if not res then log{C.R,("Failed to write file: "):format(err2 or"Unknown error")}return end + + --Delete file + if not love.filesystem.remove(arg[1])then log{C.R,("Failed to delete old file ''"):format(arg[1])}return end + + log{C.Y,("Succesfully renamed file '%s' to '%s'"):format(arg[1],arg[2])} +end commands.exit=backScene commands.quit=backScene commands.bye=backScene