C++枚举某个目录下所有文件
标签(空格分隔): iso c++
c++提供文件遍历的方法如下
一个结构体
三个函数
struct _finddata32_t
{
unsigned attrib;//文件属性
__time32_t time_create; // 创建时间
__time32_t time_access; // 最后访问时间
__time32_t time_write; //最后写入时间
_fsize_t size; //文件大小
char name[260];//文件名
};
文件有如下属性
// File attribute constants for the _findfirst() family of functions
#define _A_NORMAL 0x00 // 正常文件没有读写限制
#define _A_RDONLY 0x01 // 只读文件
#define _A_HIDDEN 0x02 // 隐藏文件
#define _A_SYSTEM 0x04 // 系统文件
#define _A_SUBDIR 0x10 // 目录
#define _A_ARCH0x20 // 存档文件
枚举文件
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
);
参数:
建议使用 Visual Studio 2017 立即下载
_findfirst、_findfirst32、_findfirst32i64、_findfirst64、_findfirst64i32、_findfirsti64、_wfindfirst、_wfindfirst32、_wfindfirst32i64、_wfindfirst64、_wfindfirst64i32、_wfindfirsti64
Visual Studio 2015 其他版本
发布日期: 2016年7月
若要了解有关 Visual Studio 2017 RC 的最新文档,请参阅 Visual Studio 2017 RC 文档。
提供有关匹配中指定的文件的文件名的第一个实例的信息filespec参数。
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返回标识的文件或与匹配的文件组的唯一的搜索句柄,可在后续调用_findnext或_findclose。 否则为_findfirst返回 –&1; 并设置errno为以下值之一。
EINVAL
无效的参数︰filespec或fileinfo已NULL。 或者,操作系统返回了意外的