我在使用 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/