Sign in to follow this  

Quickest Way To Find File Size Of File Opened With fopen()

This topic is 4776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's an example:


//open the file
FILE *FilePtr = fopen("Foo.txt", "rb");

//seek to the last byte
fseek(FilePtr, 0, SEEK_END);

//ftell returns the current file ptr position, for binary streams
//this is the number of bytes from the beginning of the file so in //this case it'll return the filesize
long FileSize = ftell(FilePtr);


May not be the quickest way to do it but it's the only way I've seen.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
while someone already suggested opening the file and using either ftell() or GetFileSize(), if speed is important to you, use FindFirstFile() instead. opening a file is always slow(er).

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
while someone already suggested opening the file and using either ftell() or GetFileSize(), if speed is important to you, use FindFirstFile() instead. opening a file is always slow(er).


To quote the topic, "Quickest Way To Find File Size Of File Opened With fopen()".

Assuming it's allready open, go with ftell (first link from google search for "ftell").

If it's not, the AP has a point, going by base execution speed (although I wouldn't say allways, as I bet someone could think of some really archaic example where this isn't the case XD).

Share this post


Link to post
Share on other sites

This topic is 4776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this