Is there any function in any of the c libraries that can read size of the file in bytes ?
I need to read file size in a program..
Is there any function in any of the c libraries that can read size of the file in bytes ?
I need to read file size in a program..
yes
ftell for example called after fseek(f,0,SEEK_END)
but note that the return value is only long...
file should be opend as binary for accurate size calculation.
MS has some extentions that can handle files with sizes that are bigger than LONG_MAX but if you go with MS extentions you can effectively call some Win32 API that will return actual file size or size on disk
Last edited by vart; 02-08-2008 at 11:53 AM.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
There is ftelli64. Don't know if it's a Microsoft extension, though.
Anyhow, to get the file size of a file through win32 api, you still need to open it through CreateFile which requires a library knowledge itself to use.
So C functions, even if extensions, are generally easier.
I'll try this out..
Thanks for a quick reply...
There was a thread recently in the Linux Programming Forum about accessing files larger than the range of a long. Look there if you're interested. There are lots of functions for doing it, of various degrees of portability, such as fgetpos()+fsetpos() from C99, and ftello(), etc.
Anyway, I don't think that's what the OP needs.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.