mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
37 lines
799 B
Lua
37 lines
799 B
Lua
|
|
local fs = require("fs")
|
||
|
|
local shell = require("shell")
|
||
|
|
|
||
|
|
local args = {...}
|
||
|
|
|
||
|
|
if #args < 2 then
|
||
|
|
io.stderr:write("usage: move <source> <destination>\n")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
local source, destination = shell.resolve(args[1]), shell.resolve(args[2])
|
||
|
|
local files = fs.find(source)
|
||
|
|
|
||
|
|
if #files > 0 then
|
||
|
|
local dir = fs.isDir(destination)
|
||
|
|
|
||
|
|
if #files > 1 and not dir then
|
||
|
|
io.stderr:write("destination must be a directory\n")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
for i=1, #files, 1 do
|
||
|
|
if dir then
|
||
|
|
fs.move(files[i], fs.combine(destination, fs.getName(files[i])))
|
||
|
|
elseif #files == 1 then
|
||
|
|
if fs.exists(destination) then
|
||
|
|
io.stderr:write("file already exists\n")
|
||
|
|
return
|
||
|
|
else
|
||
|
|
fs.move(files[i], destination)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
else
|
||
|
|
io.stderr:write("no such file(s)\n")
|
||
|
|
end
|