gpt4 book ai didi

file - Lua中如何获取文件大小和删除文件?

转载 作者:行者123 更新时间:2023-12-04 00:08:03 27 4
gpt4 key购买 nike

我在使用 Lua 获取文件大小时遇到​​问题。我正在创建一个函数方法,如果文件的文件大小为 743 bytes ,然后文件将被删除。

这是我的代码:

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) .但先关闭文件。

关于file - Lua中如何获取文件大小和删除文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10712622/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com