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);
}

C++遍历文件夹的更多相关文章

  1. C#遍历文件夹下所有文件

    FolderForm.cs的代码如下: using System; using System.Collections.Generic; using System.Diagnostics; using ...

  2. windowsAPI遍历文件夹(速度高于递归)

    #region API 遍历文件夹及其子文件夹和子文件 #region 声明WIN32API函数以及结构 ************************************** [DllImpo ...

  3. C# 遍历文件夹下所有子文件夹中的文件,得到文件名

    假设a文件夹在F盘下,代码如下.将文件名输出到一个ListBox中using System.Data;using System.Drawing;using System.Linq;using Syst ...

  4. python 遍历文件夹 文件

    python 遍历文件夹 文件   import os import os.path rootdir = "d:\data" # 指明被遍历的文件夹 for parent,dirn ...

  5. C#遍历文件夹及文件

    背景: 想自己实现一个网盘系统,于是需要用到遍历文件(夹)操作. C#基本知识梳理: 1.如何获取指定目录包含的文件和子目录 (1). DirectoryInfo.GetFiles():获取目录中(不 ...

  6. Java学习随笔3:遍历文件夹及文件的读取和写入

    import java.io.File; /** * 遍历文件夹 */ public class ScannerFile { public static void main(String[] args ...

  7. java 遍历文件夹里的文件

    Java遍历文件夹的2种方法: A.不使用递归: import java.io.File; import java.util.LinkedList; public class FileSystem { ...

  8. python遍历文件夹下的文件

    在读文件的时候往往需要遍历文件夹,python的os.path包含了很多文件.文件夹操作的方法.下面列出: os.path.abspath(path) #返回绝对路径 os.path.basename ...

  9. JAVA 遍历文件夹下的所有文件

    JAVA 遍历文件夹下的所有文件(递归调用和非递归调用) 1.不使用递归的方法调用. public void traverseFolder1(String path) { int fileNum = ...

  10. Delphi遍历文件夹

    /// <remarks> /// 遍历文件夹 (引用SysUtils单元) /// </remarks> procedure TfrmMusicMenu.SearchInDi ...

随机推荐

  1. 使用vagrant一键部署本地php开发环境(一)

    一:我们为什么需要用这玩意 我们在开发中经常会面临的问题:环境不一致,有人用Mac有人用Windos还有几个用linux的,而我们的服务器都是linux.    在我本地是可以的啊,我测了都,没有问题 ...

  2. 免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器

    免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器 Lifetime Free VPN(微劈嗯) 下载setupvpn 3.7.0的crx文件, 打开chrome的 ...

  3. 无法下载golang.org-x-net解决方法

    由于go的很多包都依赖了google官方的包,而google官方的包都在google服务器上,因为某些原因无法直接访问,在搜索了很多解决方案后,找到了最简单的一个方法: 1. 找到对应包在github ...

  4. mongodb and 和 or 查询

    db.getCollection('gxyWarnEntity').find({ "schoolId" : "f11c8ea12f457dbc19c768a8bb6357 ...

  5. Ideal常用 快捷键

    IntelliJ Idea 常用快捷键列表   Alt+回车 导入包,自动修正Ctrl+N   查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L  格式化代码 Ctrl+Alt+O 优化导 ...

  6. Python常用模块安装

    1. python操作MySQL数据库的依赖包MySQLdb ImportError: No module named MySQLdb 安装方式: yum install MySQL-python 2 ...

  7. html table设置成强制不换行

    在html文件中添加如下代码: <style type="text/css"> table td{word-break: keep-all;white-space:no ...

  8. bash小结

    context:CentOS 什么是shell? shell就是与计算机交互的接口. linux支持的shell [root@node1 ~]# cat /etc/shells /bin/sh #被 ...

  9. webdriervAPI基础元素定位

    from  selenium  import  webdriver driver  =  webdriver.Chorme() driver.get("http://www.baidu.co ...

  10. 第3课.进化后的const

    1.c语言中 const修饰的变量是只读的,本质上还是变量 const修饰的局部变量在栈上分配空间(因为在栈上分配空间,所以我们可以通过改变这个空间的值.间接去改变这个变量.) const修饰的全局变 ...