函数:file.move 移动文件

原文链接: https://luabox-book.touchsprite.com/dev_docs/8/7.html

函数名称:移动文件

函数功能:移动文件到新的目录下

函数方法

flag = file.move(path,tpath)

参数类型必填说明
path string 待移动文件的路径,
相对路径(仅支持 v1.0.6 及其以上版本)如 "ceshi.png" 表示当前流程文件夹下的 ceshi.png 文件
tpath string 要移动到的文件路径,注意先判断是否有重名文件或文件夹,
相对路径(仅支持 v1.0.6 及其以上版本)
返回值类型说明
flag boolean true - 移动成功,false - 移动失败

 

函数用例:

--相对路径,仅支持 v1.0.6 及其以上版本
--相对路径为当前流程文件夹:/sdcard/LuaBox/Projects/流程名称/
--待移动文件的路径,表示当前流程文件夹下的 222.log 文件
path = "222.log"
--要移动到的文件夹,表示当前流程文件夹下的测试文件夹
tpath = "测试/"
--判断文件是否存在
flag1 = file.isExist(path)
flag2 = file.isExist(tpath)
if  flag1 and flag2 then
      flag3=file.move(path,tpath.."error.log")
    if  flag3 then
        dialog("移动成功",5000)
    else
        dialog("移动失败",5000)
    end
else
    dialog("文件(夹)不存在",5000)
end

  

--待移动文件的路径
path = "111.lua"
--要移动到的文件夹
tpath = "测试/"
--判断文件是否存在
flag1 = file.isExist(path)
flag2 = file.isExist(tpath)
if  flag1 and flag2 then
      flag3=file.move(path,tpath.."222.lua")
    if  flag3 then
        dialog("移动成功",5000)
    else
        dialog("移动失败",5000)
    end
else
    dialog("文件(夹)不存在",5000)
end

  

注意事项

  • 待移动和要移动到的文件路径必须带文件名,文件名和扩展名可修改。

posted @ 2024-07-22 12:59  yinghualeihenmei  阅读(2)  评论(0编辑  收藏  举报