函数: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 - 移动失败

 

函数用例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--相对路径,仅支持 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

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--待移动文件的路径
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 @   yinghualeihenmei  阅读(74)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2023-07-22 SVN详细使用教程
2022-07-22 windows安全中心怎么关闭
点击右上角即可分享
微信分享提示