Can anyone remind me how to in C, get the size of a disk file WITHOUT having to open it. thank you.
Printable View
Can anyone remind me how to in C, get the size of a disk file WITHOUT having to open it. thank you.
Code:#include <sys/stat.h>
struct stat s;
_stat("MyFile.TXT", &s);
int size = s.st_size
It's not standard C, but most compilers support _stat() ...
From MSDN
Code:#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
void main( void )
{
struct _stat buf;
int result;
/* Get data associated with "stat.c": */
result = _stat( "stat.c", &buf );
/* Check if statistics are valid: */
if( result != 0 )
perror( "Problem getting information" );
else
{
/* Output some of the statistics: */
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' );
printf( "Time modified : %s", ctime( &buf.st_atime ) );
}
}