共用方式為


_stat,_wstat 函式

取得檔案的狀態資訊。

int _stat(
   const char *path,
   struct _stat *buffer 
);
int _stat32(
   const char *path,
   struct __stat32 *buffer 
);
int _stat64(
   const char *path,
   struct __stat64 *buffer 
);
int _stati64(
   const char *path,
   struct _stati64 *buffer 
);
int _stat32i64(str
   const char *path,
   struct _stat32i64 *buffer 
);
int _stat64i32(str
   const char *path,
   struct _stat64i32 *buffer 
);
int _wstat(
   const wchar_t *path,
   struct _stat *buffer 
);
int _wstat32(
   const wchar_t *path,
   struct __stat32 *buffer 
);
int _wstat64(
   const wchar_t *path,
   struct __stat64 *buffer 
);
int _wstati64(
   const wchar_t *path,
   struct _stati64 *buffer 
);
int _wstat32i64(
   const wchar_t *path,
   struct _stat32i64 *buffer 
);
int _wstat64i32(
   const wchar_t *path,
   struct _stat64i32 *buffer 
);

參數

  • path
    字串,包含現有的檔案或目錄路徑的指標。

  • buffer
    儲存結果的結構指標。

傳回值

如果取得檔案狀態資訊,每個函式會傳回 0。 傳回值為-1 表示發生錯誤,在此情況下errno設定為 [ ENOENT,表示該檔名或路徑找不到。 傳回值為EINVAL指出不正確的參數。 errno也會設定成EINVAL在此情況下。

注意事項注意事項

如果path包含位置的目錄,它不能包含尾端反斜線。如果是的話,會傳回-1 和errno將被設定成ENOENT。

請參閱 _doserrno、 errno、 _sys_errlist,以及 _sys_nerr 如需有關篩選器及其他的詳細資訊,任何傳回碼。

可以表示檔案的日期戳記,它是否晚午夜 1970 年 1 月 1 日,且前 23: 59: 59,3000 年 12 月 31,成為 UTC,除非您使用_stat32或_wstat32,或已定義_USE_32BIT_TIME_T,在此情況下代表日期,只有直到 03: 14: 07 以後 2038 年 1 月 19 日,UTC。

備註

_stat函式會取得資訊的檔案或目錄所指定的path ,並將它儲存在結構中所指buffer。 _stat會自動處理多位元組字元字串引數視需要辨識多位元組字元順序,根據目前使用中的多位元組字碼頁。

_wstat寬字元版本的_stat。 path引數為_wstat是寬字元字串。 _wstat與_stat運作方式完全相同,除了_wstat不處理多位元組字元字串。

這些函式的變體支援 32 位元或 64 位元時間型別和 32 位元或 64 位元檔案長度。 第一個數字的後置字元 (32或64) 表示的時間使用的型別 ; 大小 第二個字尾是i32或i64,表示檔案大小是否表示為 32 位元或 64 位元的整數。

_stat相當於_stat64i32,以及struct_stat包含 64 位元的時間。 在此情況除非_USE_32BIT_TIME_T定義時,在這種情況的舊的行為是作用中。 _stat使用一個 32 位元的時間,以及struct_stat包含 32 位元的時間。 也是一樣的_stati64。

注意事項注意事項

_wstat將不能Windows Vista符號連結。在這些情況下, _wstat一定會報告檔案大小為 0。_stat運作正常的符號連結。

這個函式會驗證它的參數。 如果其中一個path或buffer是NULL,不正確的參數處理常式會叫用,如所述參數驗證

時間類型和檔案長度型別不同的 _stat

功能

定義的 _USE_32BIT_TIME_T?

時間類型

檔案長度的型別

_stat, _wstat

未定義

64 位元

32 位元

_stat, _wstat

已定義

32 位元

32 位元

_stat32, _wstat32

不會受到巨集定義

32 位元

32 位元

_stat64, _wstat64

不會受到巨集定義

64 位元

64 位元

_stati64, _wstati64

未定義

64 位元

64 位元

_stati64, _wstati64

已定義

32 位元

64 位元

_stat32i64, _wstat32i64

不會受到巨集定義

32 位元

64 位元

_stat64i32, _wstat64i32

不會受到巨集定義

64 位元

32 位元

泛用文字常式對應

TCHAR。H 常式

_UNICODE & 未定義的 _MBCS

定義的 _MBCS

定義 _unicode 之後

_tstat

_stat

_stat

_wstat

_tstat64

_stat64

_stat64

_wstat64

_tstati64

_stati64

_stati64

_wstati64

_tstat32i64

_stat32i64

_stat32i64

_wstat32i64

_tstat64i32

_stat64i32

_stat64i32

_wstat64i32

_stat SYS\STAT 中所定義的結構。H,包含下列欄位。

  • st_gid
    群組擁有的檔案 (特定的 UNIX),這個欄位的數字識別項一定會在 Windows 系統上的零。 重新導向的檔案會被歸類為 Windows 檔案。

  • st_atime
    檔案的上次存取時間。 有效期 NTFS 但未開啟 FAT 格式化磁碟機。

  • st_ctime
    建立檔案的時間。 有效期 NTFS 但未開啟 FAT 格式化磁碟機。

  • st_dev
    磁碟機內含檔案的磁碟數目 (相同的st_rdev)。

  • st_ino
    資訊節點的數目 ( inode) 檔案 (特定的 UNIX)。 在 UNIX 的檔案系統, inode說明檔案日期和時間戳記、 權限,以及內容。 當強式連結至另一個檔案,它們會共用相同inode。 inode,因此st_ino,FAT、 HPFS 或 NTFS 檔案系統中不具任何意義。

  • st_mode
    檔案模式資訊的位元遮罩。 _S_IFDIR位元如果設定path指定的目錄中。 _S_IFREG位元如果設定path指定一般的檔案或裝置。 使用者讀取/寫入的位元是根據檔案的權限模式 ; 顯示設定 使用者執行位元根據檔名的副檔名設定。

  • st_mtime
    檔案的上次修改時間。

  • st_nlink
    在非 NTFS 檔案系統一律為 1。

  • st_rdev
    磁碟機內含檔案的磁碟數目 (相同的st_dev)。

  • st_size
    檔案的大小以位元組為單位。 64 位元的整數,與變化i64尾碼**.**

  • st_uid
    使用者擁有檔案 (特定的 UNIX) 的數值識別碼。 此欄位一定會在 Windows 系統上的零。 重新導向的檔案會被歸類為 Windows 檔案。

如果path是指一種裝置, st_size,各種時間欄位, st_dev,以及st_rdev中的欄位_stat結構沒有意義。 因為狀態。H 使用 _dev_t 別中定義的型別。H,您必須包含型別。H 之前的狀態。在程式碼中的 H。

需求

常式

所需的標頭

選擇性標頭

_stat, _stat32, _stat64, _stati64, _stat32i64, _stat64i32

<sys/types.h> 後面接著 <sys/stat.h>

<errno.h>

_wstat, _wstat32, _wstat64, _wstati64, _wstat32i64, _wstat64i32

<sys/types.h> 後面接著 <sys/stat.h> 或者 <wchar.h>

<errno.h>

其他的相容性資訊,請參閱相容性在簡介中。

範例

// crt_stat.c
// This program uses the _stat function to
// report information about the file named crt_stat.c.
 
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>

int main( void )
{
   struct _stat buf;
   int result;
   char timebuf[26];
   char* filename = "crt_stat.c";
   errno_t err;

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

   // Check if statistics are valid: 
   if( result != 0 )
   {
      perror( "Problem getting information" );
      switch (errno)
      {
         case ENOENT:
           printf("File %s not found.\n", filename);
           break;
         case EINVAL:
           printf("Invalid parameter to _stat.\n");
           break;
         default:
           /* Should never be reached. */
           printf("Unexpected error in _stat.\n");
      }
   }
   else
   {
      // 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);
      if (err)
      {
         printf("Invalid arguments to ctime_s.");
         exit(1);
      }
      printf( "Time modified : %s", timebuf );
   }
}
  

.NET Framework 對等用法

請參閱

參考

檔案處理

_access _waccess

_fstat、 _fstat32、 _fstat64、 _fstati64、 _fstat32i64、 _fstat64i32

_getmbcp

_setmbcp