如何获取文件大小和删除文件在Lua?

我有使用Lua获取文件大小的问题.我正在创建一个函数方法,如果文件的文件大小是743字节,那么该文件将被删除.

这是我的代码:

local getDLFile = function(fileToDL)
            local path = system.pathForFile(fileToDL,system.DocumentsDirectory )
            local myFile = io.open( path,"w+b" ) 
            http.request{ 
                url = "http://www.testfile.com/"..fileToDL,sink = ltn12.sink.file(myFile),}

            -- i don't know what is the syntax
            if myFile.size == 743 bytes then
                 myFile.delete
            end             

end

任何人都可以帮助我关于我的情况吗?

解决方法

大小由myFile:seek(“end”)给出.

要删除文件,请使用os.remove(path).但先关闭文件.

相关文章

1.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...