Getting File Size
Does anyone know a fast way of getting a file''s size?
I suppose it could be done by reading 1 byte at a time and waiting for fread to stop reading..
Anyone know a better way?
------------------------------------------------------------I wrote the best video game ever, then I woke up...
FILE *fp = fopen("FileName","r"); // Open the file
fseek(fp,0,SEEK_END); // Go to end
fgetpos(fp,&pos); // Get position
printf("#Bytes = %ld",pos); // Output length
fseek(fp,0,SEEK_SET); // Go back to the beginning if you want
fseek(fp,0,SEEK_END); // Go to end
fgetpos(fp,&pos); // Get position
printf("#Bytes = %ld",pos); // Output length
fseek(fp,0,SEEK_SET); // Go back to the beginning if you want
LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360
Use filelength().
When life hands you lemons, throw them at God''s head.
int handle;int length;handle = open("myfile.txt", O_CREAT);length = filelength(handle);close(handle);
When life hands you lemons, throw them at God''s head.
The Win32 way:
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
HANDLE file;DWORD FileSize;file = CreateFile("file.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);FileSize = GetFileSize(file, (LPDWORD)NULL);CloseHandle(file);
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
The real(tm) way
savepos = ftell(somefile);
fseek(somefile, 0, SEEK_END);
fsize = ftell(somefile);
fseek(somefile, savepos, SEEK_SET);
return(fsize);
-Mezz
savepos = ftell(somefile);
fseek(somefile, 0, SEEK_END);
fsize = ftell(somefile);
fseek(somefile, savepos, SEEK_SET);
return(fsize);
-Mezz
December 31, 2000 10:30 PM
The way that Mezz gives is IMO the best becuase it uses ANSI functions. filelength isn''t supported on all systems, etc....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement