如何获取文件大小和删除文件在Lua? [英] How to get the file size and delete file in Lua?
本文介绍了如何获取文件大小和删除文件在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),
}
- 我不知道语法是什么
if myFile .size == 743 bytes然后
myFile.delete
结束
$ b $结束
任何人都可以帮我解释我的情况吗?
解决方案
大小由 myFile:seek(end)
。
要删除文件,使用 os.remove )
。但是先关闭文件。
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.
Here is my code :
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?
解决方案
The size is given by myFile:seek("end")
.
To delete the file, use os.remove(path)
. But close the file first.
这篇关于如何获取文件大小和删除文件在Lua?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文