Learn when you want, where you want with convenient online training courses. Sign up now!
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
int main( void )
struct _stat buf;
char* filename = "crt_stat.c";
// Get data associated with "crt_stat.c":
result = _stat( filename, &buf );
// Check if statistics are valid:
if( result != 0 )
perror( "Problem getting information" );
printf("File %s not found.\n", filename);
printf("Invalid parameter to _stat.\n");
/* Should never be reached. */
printf("Unexpected error in _stat.\n");
// Output some of the statistics:
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' );
err = ctime_s(timebuf, 26, &buf.st_mtime);
printf("Invalid arguments to ctime_s.");
printf( "Time modified : %s", timebuf );
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
or '_stat()' (http://msdn.microsoft.com/en-us/library/14h5k7ff.aspx) if you are on Windows,
bool FileExists(const char * szpath)
struct stat fs;
return stat(szpath, &fs) == 0;
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.