stat(linux),_stat, _wstat, _stati64, _wstati64 获取文件信息

原创 2006年05月30日 17:48:00

Get status information on a file.

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

__int64 _stati64( const char *path, struct _stat *buffer );

int _wstat( const wchar_t *path, struct _stat *buffer );

__int64 _wstati64( const wchar_t *path, struct _stat *buffer );

Routine Required Header Optional Headers Compatibility
_stat <sys/types.h> followed by <sys/stat.h> <errno.h> Win 95, Win NT
_wstat <sys/types.h> followed by <sys/stat.h> or <wchar.h> <errno.h> Win NT
_stati64 <sys/types.h> followed by <sys/stat.h> <errno.h> Win 95, Win NT
_wstati64 <sys/types.h> followed by <sys/stat.h> or <wchar.h> <errno.h> Win NT

For additional compatibility information, see Compatibility in the Introduction.


LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns 0 if the file-status information is obtained. A return value of –1 indicates an error, in which case errno is set to ENOENT, indicating that the filename or path could not be found.



Path of existing file


Pointer to structure that stores results


The _stat function obtains information about the file or directory specified by path and stores it in the structure pointed to by buffer. _stat automatically handles multibyte-character string arguments as appropriate, recognizing multibyte-character sequences according to the multibyte code page currently in use.

_wstat is a wide-character version of _stat; the path argument to _wstat is a wide-character string. _wstat and _stat behave identically except that _wstat does not handle multibyte-character strings.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tstat _stat _stat _wstat
_tstati64 _stati64 _stati64 _wstati64

The _stat structure, defined in SYS/STAT.H, includes the following fields.


Numeric identifier of group that owns file (UNIX-specific) This field will always be zero on NT systems. A redirected file is classified as an NT file.


Time of last access of file.


Time of creation of file.


Drive number of the disk containing the file (same as st_rdev).


Number of the information node (the inode) for the file (UNIX-specific). On UNIX file systems, the inode describes the file date and time stamps, permissions, and content. When files are hard-linked to one another, they share the same inode. The inode, and therefore st_ino, has no meaning in the FAT, HPFS, or NTFS file systems.


Bit mask for file-mode information. The _S_IFDIR bit is set if path specifies a directory; the _S_IFREG bit is set if path specifies an ordinary file or a device. User read/write bits are set according to the file’s permission mode; user execute bits are set according to the filename extension.


Time of last modification of file.


Always 1 on non-NTFS file systems.


Drive number of the disk containing the file (same as st_dev).


Size of the file in bytes; a 64-bit integer for _stati64 and _wstati64


Numeric identifier of user who owns file (UNIX-specific). This field will always be zero on NT systems. A redirected file is classified as an NT file.

If path refers to a device, the size, time, _dev, and _rdev fields in the _stat structure are meaningless. Because STAT.H uses the _dev_t type that is defined in TYPES.H, you must include TYPES.H before STAT.H in your code.


/* STAT.C: This program uses the _stat function to
 * report information about the file named STAT.C.

#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

void main( void )
   struct _stat buf;
   int result;
   char buffer[] = "A line to output";

   /* Get data associated with "stat.c": */
   result = _stat( "stat.c", &buf );

   /* Check if statistics are valid: */
   if( result != 0 )
      perror( "Problem getting information" );
      /* 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 ) );


File size     : 745
Drive         : C:
Time modified : Tue May 03 00:00:00 1994

File Handling Routines

See Also   _access, _fstat, _getmbcp, _setmbcp


c++获取文件信息——_stat函数的使用 _stat函数的功能 _stat函数用来获取指定路径的文件或者文件夹的信息。 函数声明 int _stat( const char *path, ...
  • frank_liuxing
  • frank_liuxing
  • 2014年01月21日 15:31
  • 20193

获取文件信息函数:_stat, _stat64, _stati64, _wstat, _wstat64, _wstati64

Get status information on a file. int _stat( const char *path, struct _stat *buffer ...
  • jackie_lee2011
  • jackie_lee2011
  • 2013年08月02日 00:27
  • 3380


stat函数讲解 表头文件:    #include                    #include 定义函数:    int stat(const char *file_name, st...
  • yuan_hong_wei
  • yuan_hong_wei
  • 2015年12月14日 14:09
  • 557

Linux stat命令总结

简介Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Members...
  • lmb55
  • lmb55
  • 2017年12月29日 19:00
  • 82

linux C之stat()

头文件:    #include #include 定义函数:    int stat(const char *file_name, struct stat *buf); 函数说明:...
  • laurawan
  • laurawan
  • 2013年04月28日 20:40
  • 10268


 Get status information on a _stat( const char *path, struct _stat *buffer );__int64 _stati...
  • rabbit729
  • rabbit729
  • 2008年12月17日 13:20
  • 3397

在Window 10 64位电脑上安装 OpenSSL安装过程

前期准备 安装最新版的ActivePerl 到 下载最新OpenSSL源码 到 下载NASM汇编工具 在开始任务栏里打...
  • jzjwonderful
  • jzjwonderful
  • 2016年11月23日 15:22
  • 3696

Linux stat 获取文件属性

获取文件的属性 $stat filename 获取文件系统信息 $stat -f /dev/sda1   #此获取的是文件系统(分区),而不是文件 stat支持许多取得文件属性...
  • halou90
  • halou90
  • 2016年01月29日 14:08
  • 323


stat命令查看文件的信息: stat查看文件信息的三个时间点 (1)Access:文件访问时间,读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more,cat,less, head,t...
  • wenqiang1208
  • wenqiang1208
  • 2017年02月14日 20:26
  • 214


核心 1、什么是stat命令 2、stat的格式 3、stat的基本操作 4、stat的案例1、什么是stat命令 stat指令:文件/文件系统的详细信息显示。 stat命令主要用于显示文...
  • paicMis
  • paicMis
  • 2017年03月05日 22:31
  • 1384
您举报文章:stat(linux),_stat, _wstat, _stati64, _wstati64 获取文件信息