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?
To delete the file, use os. remove(path) .
The flush function executes all pending writes to a file. Like the write function, you can call it as a function, io. flush() , to flush the current output file; or as a method, f:flush() , to flush file f . The seek function can be used both to get and to set the current position of a file.
A LUA file contains source code written in Lua, a light-weight programming language designed for extending or adding functionality to software applications. The Lua scripting language syntax is simple but supports a large number of data types and operators.
The size is given by myFile:seek("end")
.
To delete the file, use os.remove(path)
. But close the file first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With