Friday, December 6, 2013

_stat,_fstat windows

int _stat(const char *path,struct _stat *buffer );

When you use _stat function to obtain information about a file, and would like to determine if the file is a directory or regular file? You can use the below example:
#include  "sys/types.h"
#include  "sys/stat.h"

int main()
{
      struct  _stat   file_stat;
      if (!_stat(file_name_with_path, &file_stat))
     {
          if( (file_stat.st_mode & S_IFMT ) ==_S_IFDIR  )
          {
                 printf( "Info [%s] is directory continue\n", file_name_with_path);
               continue;
          }
    }
    else
   {
          printf( "Error Unable to Obtain File Stats[%s]\n", file_name_with_path);
   }
}



No comments:

Post a Comment