Quickest Way To Find File Size Of File Opened With fopen()
'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
Skizz
Here's an example:
May not be the quickest way to do it but it's the only way I've seen.
//open the fileFILE *FilePtr = fopen("Foo.txt", "rb");//seek to the last bytefseek(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 filesizelong FileSize = ftell(FilePtr);
May not be the quickest way to do it but it's the only way I've seen.
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement