Lua中如何获取文件大小和删除文件? [英] How to get the file size and delete file in Lua?
本文介绍了Lua中如何获取文件大小和删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 Lua 获取文件大小时遇到问题.我正在创建一个函数方法,如果文件的文件大小为743 bytes
,那么该文件将被删除.
I have problem in getting the size of the file using Lua. I am creating a function method that if the file size of the file is 743 bytes
, then the file will be deleted.
这是我的代码:
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
有人可以帮我处理我的案子吗?
Can anyone can help me about my case?
推荐答案
大小由 myFile:seek("end")
给出.
要删除文件,请使用os.remove(path)
.但先关闭文件.
To delete the file, use os.remove(path)
. But close the file first.
这篇关于Lua中如何获取文件大小和删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文