struct _finddata_t
{
unsigned attrib; //文件属性
time_t time_create; //文件创建时间
time_t time_access; //文件上一次访问时间
time_t time_write; //文件上一次修改时间
_fsize_t size; //文件字节数
char name[_MAX_FNAME]; //文件名
};

文件属性是无符号整数,取值为相应的宏:_A_ARCH(存档),_A_SUBDIR(文件夹),_A_HIDDEN(隐藏),_A_SYSTEM(系统),_A_NORMAL(正常),_A_RDONLY(只读)。

以下函数,我们可以将文件信息存储到这个结构体中:

 //按FileName命名规则匹配当前目录第一个文件
_findfirst(_In_ const char * FileName, _Out_ struct _finddata64i32_t * _FindData);
//按FileName命名规则匹配当前目录下一个文件
_findnext(_In_ intptr_t _FindHandle, _Out_ struct _finddata64i32_t * _FindData);
//关闭_findfirst返回的文件句柄
_findclose(_In_ intptr_t _FindHandle);

_findfirst 函数返回的是匹配到文件的句柄,数据类型为long。

 #include "io.h"
void dfs_folder(std::string pathname, std::ofstream &fout)
{
_finddata_t file; std::string findpath = pathname + "\\*"; long handle = _findfirst(findpath.c_str(), &file); if(handle == -1L)
{
std::cerr << "can not match the folder path" <<std::endl;
std::cout << pathname << std::endl;
system("PAUSE");
exit(-);
} do
{
if(file.attrib & _A_SUBDIR)
{
if( (strcmp(file.name, ".") != ) && (strcmp(file.name, "..") != ) )
{
std::string newpath = pathname + "\\" + file.name;
dfs_folder(newpath, fout);
}
}
else
{
//std::cout << pathname + "\\" + file.name << std::endl;
fout << file.name << std::endl;
}
}while( _findnext(handle, &file) == ); _findclose(handle);
}

最新文章

  1. 【Learning Python】【第二章】Python基础类型和基础操作
  2. XFire最佳实践
  3. Replication的犄角旮旯(七)-- 一个DDL引发的血案(下)(聊聊logreader的延迟)
  4. mysql 密码篇
  5. 升级MySQL支持utf8mb4字符集详细步骤
  6. Codeforces Round #365 (Div. 2)-D Mishka and Interesting sum(树状数组)
  7. javascript实现数据结构与算法系列:队列 -- 链队列和循环队列实现及示例
  8. Uva592 Island of Logic
  9. jquery操作iframe
  10. 编程算法 - 切割排序 代码(C)
  11. Mybatis基本用法--上
  12. python 三元运算符、推导式、递归、匿名函数、内置函数
  13. Tarjan求割点(割顶) 割边(桥)
  14. Mybatis Cause: java.lang.ClassNotFoundException: Cannot find class:
  15. MathExam
  16. 枚举子窗口EnumChildWindows()的应用
  17. zabbix 报警方式之 微信公众号报警(5)
  18. Sql Server Profiler使用
  19. 如何在WIN7_64环境下安装Oracle10g_64位版本
  20. Mysql 按条件排序查询一条记录 top 1 对应Mysql的LIMIT 关键字

热门文章

  1. 如何构建自己的docker镜像
  2. Flutter移动电商实战 --(32)列表页_小类高亮交互效果制作
  3. C之指针
  4. centos 开启关闭网卡
  5. linux - mysql:查看 mysql 是否安装成功
  6. Eclipse项目修改编译jdk版本(Failed to read candidate component class: file 处理)
  7. SpringBoot学习之一 Unable to find a single main class from the following candidates
  8. Spring Cloud(6):保护微服务(Security) - OAuth2.0
  9. 清理mac缓存
  10. ffmpeg学习笔记-初识ffmpeg