Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a file size in VC++ 6.0

Status
Not open for further replies.

mjc106

IS-IT--Management
Jan 26, 2001
2
CA
Hi,

Sorry if there is a recent post about this but the Keyword Search is down.

Anyway I was wondering, is there some library function that will give just the a file size in bytes. I.e. In (for example) stdio.h call int getsize(FILE*) would return the size of a file pointed to by the file pointer?

I would like, as much as possible to stick to straight up ANSI C for ease of portability, but anything that works would be welcome at this point. M$'s MSDN is worse than useless and I am hoping that non Micoserfs can be a little more helpful. :)

Thanx in advance for any bright ideas. :)

Michael
 
Michael,

Well it's been a while but I think you use fseek() to move the file pointer to the end of the file, I believe there is a defined constant that is used in one of the arguments as the starting position to 'seek from'... so something like this:

fseek(pFile, 0, SEEK_END);

then use ftell() to return the position. There might be some differences in how this method works depending on the 'open mode'. I would think you would want to use binary.

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top