函数:copyfile 复制文件

--复制文件
function copyfile(path,to)
    os.execute("cp -rf "..path.." "..to);
end

参数说明

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

函数用例

如要复制 res/1.txt 到 lua/1.txt,则输入:

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

results matching ""

    No results matching ""