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

Started by
5 comments, last by MaulingMonkey 19 years, 5 months ago
Whats the quickest way to do this. regards ace
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
Here's an example:

//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.
Look up GetFileSize().
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
hehe, u never guess what i used to do,

read bytes till the ens is found
LOLOLOLOLOL


ace
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