|
-
July 21st, 2003, 01:01 PM
#1
File size w/o opening file
Can anyone remind me how to in C, get the size of a disk file WITHOUT having to open it. thank you.
-
July 21st, 2003, 01:06 PM
#2
Code:
#include <sys/stat.h>
struct stat s;
_stat("MyFile.TXT", &s);
int size = s.st_size
-
July 21st, 2003, 01:08 PM
#3
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 ) );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|