Saturday, June 12, 2010

How to get a file size?

stat structure is the guy to retrieve the file information, and this structure has a field called st_size where this field will retrieve the file size in bytes.

Here is the sample code:

struct stat FileStat;
if( stat( "MyFile", &FileStat ) == 0 ) { cout << FileStat.st_size << endl; }

No comments: