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

前端之家收集整理的这篇文章主要介绍了如何获取文件大小和删除文件在Lua?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有使用Lua获取文件大小的问题.我正在创建一个函数方法,如果文件文件大小是743字节,那么该文件将被删除.

这是我的代码

  1. local getDLFile = function(fileToDL)
  2. local path = system.pathForFile(fileToDL,system.DocumentsDirectory )
  3. local myFile = io.open( path,"w+b" )
  4. http.request{
  5. url = "http://www.testfile.com/"..fileToDL,sink = ltn12.sink.file(myFile),}
  6.  
  7. -- i don't know what is the Syntax
  8. if myFile.size == 743 bytes then
  9. myFile.delete
  10. end
  11.  
  12. end

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

解决方法

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

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

猜你在找的Lua相关文章