Jump to content
  • Advertisement
Sign in to follow this  
dave

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

This topic is 5058 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

Advertisement
'Quickest' is a bit ambiguous - are you talking about execution speed of time taken to write the code? Whichever, look up the ftell function.

Skizz

Share this post


Link to post
Share on other sites
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
hehe, u never guess what i used to do,

read bytes till the ens is found
LOLOLOLOLOL


ace

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!