movefile 移动文件

--移动文件
function movefile(path,to)
    os.execute("mv "..path.." "..to);
end

参数说明

参数 类型 必填 说明
path string 待移动文件的路径,支持 * 通配符
to string 要移动到的文件路径,注意先判断是否有重名文件或文件夹

函数用例

如要移动 res 文件夹下的 1.txt 到 lua 文件夹下,则输入:

--移动文件
function movefile(path,to)
    os.execute("mv "..path.." "..to);
end
--检测指定文件是否存在
function file_exists(file_name)
    local f = io.open(file_name, "r")
    return f ~= nil and f:close()
end
oldpath = userPath().."/res/1.txt"
newpath = userPath().."/lua/1.txt"
bool = file_exists(oldpath)
if bool then
    movefile(oldpath,newpath)
else
    dialog("文件不存在")
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""