_findfirst、_wfindfirst

提供有关与 filespec 参数中指定的文件 filename 的实例的信息。

intptr_t _findfirst(
   const char *filespec,
   struct _finddata_t *fileinfo 
);
intptr_t _findfirst32(
   const char *filespec,
   struct _finddata32_t *fileinfo 
);
intptr_t _findfirst64(
   const char *filespec,
   struct _finddata64_t *fileinfo 
);
intptr_t _findfirsti64(
   const char *filespec,
   struct _finddatai64_t *fileinfo 
);
intptr_t _findfirst32i64(
   const char *filespec,
   struct _finddata32i64_t *fileinfo 
);
intptr_t _findfirst64i32(
   const char *filespec,
   struct _finddata64i32_t *fileinfo 
);
intptr_t _wfindfirst(
   const wchar_t *filespec,
   struct _wfinddata_t *fileinfo 
);
intptr_t _wfindfirst32(
   const wchar_t *filespec,
   struct _wfinddata32_t *fileinfo 
);
intptr_t _wfindfirst64(
   const wchar_t *filespec,
   struct _wfinddata64_t *fileinfo 
);
intptr_t _wfindfirsti64(
   const wchar_t *filespec,
   struct _wfinddatai64_t *fileinfo 
);
intptr_t _wfindfirst32i64(
   const wchar_t *filespec,
   struct _wfinddata32i64_t *fileinfo 
);
intptr_t _wfindfirst64i32(
   const wchar_t *filespec,
   struct _wfinddata64i32_t *fileinfo 
);

参数

  • filespec
    目标文件规范 (可以包括通配符)。

  • fileinfo
    文件信息缓冲区。

返回值

如果成功,则 _findfirst 返回标识匹配 filespec 规范,可在后续调用到 _findnext 或 _findclose文件的或组的搜索单个处理。 否则,_findfirst 返回 - 1 并将 errno 设置为以下值之一。

  • EINVAL
    无效参数 filespec 或 fileinfo为NULL。 或者,操作系统返回无法预料的错误。

  • ENOENT
    不能匹配的文件大小。

  • ENOMEM
    内存不足。

  • EINVAL
    无效文件名规范或给定的文件名大于 MAX_PATH。

有关这些属性和其他的更多信息返回代码示例,请参见 _doserrno、errno、_sys_errlist 和 _sys_nerr

如果传递的是无效参数,则这些函数调用无效参数处理程序,正如 参数验证 所述。

备注

在完成使用 _findfirst 或 _findnext 函数后(或任何变量),必须调用 _findclose。 这将释放在你的应用程序中使用这些函数的资源。

带有 w 前缀的这些函数变量是宽字符版本;否则,它们与对应的单字节函数相同。

这些函数的变量支持 32 位或 64 位时间类型和 32 位或 64 位文件大小。 第一个数字后缀 (32 或 64) 指示使用的时间类型的大小;第二个后缀要么是 i32 要么是 i64,指示文件大小是否表示为 32 位或 64 位整数。 有关哪些版本支持 32 位和 64 位时间类型和文件大小的详细信息,请参阅下表。 i32 或 i64 后缀省略,如果相同时间类型的范围,因此,_findfirst64 还支持 64 位文件长度,_findfirst32 仅支持 32 位文件长度。

这些函数为 fileinfo 参数使用大量 _finddata_t 结构。 有关 _find、_wfind 函数 类的更多信息,请参见。

使用 64 位时类型的变体允许通过 23:59 将表示的文件创建日期:59,3000 年 12 月 31 日,UTC。 使用 32 位时类型的那些通过 19:14 只表示日期:07 年 1 月 18 日 2038 年,UTC。 1970 年 1 月 1 日 00:00:00,是所有这些函数的下限的日期范围。

除非出于特定原因需要使用显式指定时间范围的版本,使用 _findfirst 或 _wfindfirst,或者,如果需要支持大于3 GB的文件大小,请使用 _findfirsti64 或 _wfindfirsti64。 所有这些函数使用 64 位时间类型。 在早期版本中,这些函数使用了 32 位时类型。 如果这是应用程序的重大更改,您可能定义 _USE_32BIT_TIME_T 获取旧行为。 如果定义 _USE_32BIT_TIME_T ,_findfirst、_finfirsti64 和它们对应的 Unicode 版本使用 32 位时间。

_findnext 的时间类型和文件长度键入变量

函数

已定义 _USE_32BIT_TIME_T?

时间类型

文件长度类型

_findfirst, _wfindfirst

未定义

64 位

32 位

_findfirst, _wfindfirst

已定义

32 位

32 位

_findfirst32, _wfindfirst32

不受定义宏影响

32 位

32 位

_findfirst64, _wfindfirst64

不受定义宏影响

64 位

64 位

_findfirsti64, _wfindfirsti64

未定义

64 位

64 位

_findfirsti64, _wfindfirsti64

已定义

32 位

64 位

_findfirst32i64, _wfindfirst32i64

不受定义宏影响

32 位

64 位

_findfirst64i32, _wfindfirst64i32

不受定义宏影响

64 位

32 位

一般文本例程映射

Tchar.h 例程

未定义 _UNICODE 和 _MBCS

已定义 _MBCS

已定义 _UNICODE

_tfindfirst

_findfirst

_findfirst

_wfindfirst

_tfindfirst32

_findfirst32

_findfirst32

_wfindfirst32

_tfindfirst64

_findfirst64

_findfirst64

_wfindfirst64

_tfindfirsti64

_findfirsti64

_findfirsti64

_wfindfirsti64

_tfindfirst32i64

_findfirst32i64

_findfirst32i64

_wfindfirst32i64

_tfindfirst64i32

_findfirst64i32

_findfirst64i32

_wfindfirst64i32

要求

功能

必需的标头

_findfirst

<io.h>

_findfirst32

<io.h>

_findfirst64

<io.h>

_findfirsti64

<io.h>

_findfirst32i64

<io.h>

_findfirst64i32

<io.h>

_wfindfirst

<io.h> or <wchar.h>

_wfindfirst32

<io.h> or <wchar.h>

_wfindfirst64

<io.h> or <wchar.h>

_wfindfirsti64

<io.h> or <wchar.h>

_wfindfirst32i64

<io.h> or <wchar.h>

_wfindfirst64i32

<io.h> or <wchar.h>

有关更多兼容性信息,请参见“简介”中的兼容性

.NET Framework 等效项

System::IO::DirectoryInfo::GetFiles

请参见

参考

系统调用

_find、_wfind 函数