lua-users home
lua-l archive

Re: How to get file size?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2011年4月19日 04:26:46 -0500, Jeff Pohlmeyer
<yetanothergeek@gmail.com> wrote:
>Note that you need to pass a file opened with io.open("your filename")
>to the function. My guess is you are trying to give it a string.
Thanks for the tip. The page doesn't mention this. After making the
change, I'm getting the error "attempt to index local 'file' (a nil
value)" on line 2:
=========== funcs.lua
function fsize (file)
 local current = file:seek() -- get current position
 local size = file:seek("end") -- get file size
 file:seek("set", current) -- restore position
 return size
end
=========== checklibs.lua
dofile("funcs.lua")
libs_file = io.open("librt.so.0","r")
print(fsize(libs_file))
libs_file:close()
===========
Am I missing some module it needs for file operation?

AltStyle によって変換されたページ (->オリジナル) /