VC++实现遍历指定文件夹,并进行深度遍历,一级,二级。。。最终列出该文件夹下所有文件全路径。

#include "stdafx.h"
#include <iostream>
#include <Windows.h> using namespace std; /************************************
@ Brief: 判断文件是否存在
@ Author: woniu201
@ Created: 2018/09/12
@ Return:
************************************/
BOOL IsDirExist(char* csDir)
{
DWORD dwAttrib = GetFileAttributes(csDir);
return INVALID_FILE_ATTRIBUTES != dwAttrib && 0 != (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
} /************************************
@ Brief: 遍历文件夹
@ Author: woniu201
@ Created: 2018/09/13
@ Return:
************************************/
BOOL DirectoryList(char* path)
{
WIN32_FIND_DATA FindData;
HANDLE handle; char fullName[2048] = {0}; char filePathName[2048] = {0};
strcpy(filePathName, path);
strcat(filePathName, "\\*.*");
handle = FindFirstFile(filePathName, &FindData);
if (handle == INVALID_HANDLE_VALUE)
{
cout << "搜索失败" << endl;
}
while(FindNextFile(handle, &FindData))
{
//过滤.和..
if (strcmp(FindData.cFileName, ".") == 0 || strcmp(FindData.cFileName, "..") == 0)
{
continue;
} sprintf(fullName, "%s\\%s", path, FindData.cFileName);
cout << fullName << endl; //判断是否是文件夹
if (IsDirExist(fullName))
{
DirectoryList(fullName);
}
}
FindClose(handle);
return TRUE;
} int _tmain(int argc, _TCHAR* argv[])
{
DirectoryList("c:\\");
getchar();
return 0;
}

VC++实现遍历指定文件夹的更多相关文章

  1. C#遍历指定文件夹中的所有文件(转)

    原文链接:http://www.cnblogs.com/qianqianfy/archive/2009/07/08/1518974.html 1. C#遍历指定文件夹中的所有文件 DirectoryI ...

  2. C#遍历指定文件夹中的所有文件(转)

    C#遍历指定文件夹中的所有文件 DirectoryInfo TheFolder=new DirectoryInfo(folderFullName);//遍历文件夹foreach(DirectoryIn ...

  3. Java 遍历指定文件夹及子文件夹下的文件

    Java 遍历指定文件夹及子文件夹下的文件 /** * 遍历指定文件夹及子文件夹下的文件 * * @author testcs_dn * @date 2014年12月12日下午2:33:49 * @p ...

  4. Jquery EasyUI tree 的异步加载(遍历指定文件夹,根据文件夹内的文件生成tree)

    private void SMT(HttpContext context) { string SqlConnection82 = System.Configuration.ConfigurationM ...

  5. C#遍历指定文件夹中的所有文件和子文件夹

    参考:http://www.cnblogs.com/skylaugh/archive/2012/09/23/2698850.html DirectoryInfo TheFolder=new Direc ...

  6. C#遍历指定文件夹中的所有文件

    DirectoryInfo TheFolder=new DirectoryInfo(folderFullName);//遍历文件夹foreach(DirectoryInfo NextFolder in ...

  7. PHP递归遍历指定文件夹内的文件

    今天早上在地铁上看了关于文件和文件夹的一章,正好最近刚搞懂linux的文件系统,觉得对文件属性的访问跟Shell命令很像,所以想晚上来实践一下. 发现php的文件夹函数好像没有提供遍历文件夹下的所有文 ...

  8. Python3遍历指定文件夹下所有文件及文件夹

    采用os模块儿: import os def get_filelist(dir): for home, dirs, files in os.walk(dir): print("####### ...

  9. C# 读取指定文件夹中的全部文件,并按规则生成SQL语句!

    本实例的目的在于: 1 了解怎样遍历指定文件夹中的全部文件 2 控制台怎样输入和输出数据 代码: using System; using System.IO; namespace ToSql{ cla ...

随机推荐

  1. 一个Maven项目在eclipse中正常,但在IDEA中启动时报错

    这个项目十有八九最初是在ecplise创建的,框架上十有八九整合了Mybatis,报的错误十有八九是 org.apache.ibatis.binding.BindingException: Inval ...

  2. 请写出一段python代码实现删除list里面的重复元素?

    l1 = ['b','c','d','c','a','a'] l2 = list(set(l1)) print(l2)

  3. python 查看某个模块都有什么方法

    1.看官方文档 https://docs.python.org/3/search.html?q=os&check_keywords=yes&area=default 2.看源码 3.d ...

  4. vue组件的原理

    https://www.cnblogs.com/landeanfen/p/6518679.html

  5. RK3288 st7703 mipi屏指令过长,程序跑飞

    本文为博主原创文章,转载请注明出处:https://www.cnblogs.com/lialong1st/p/11218433.html CPU:RK3288 系统:Android 5.1 调试 mi ...

  6. [转]解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).

    Git fetch和git pull的区别: 都可以从远程获取最新版本到本地 1.Git fetch:只是从远程获取最新版本到本地,不会merge(合并) $:git fetch origin mas ...

  7. SQLite3中的日期时间函数使用小结

    代码如下: import sqlite3conn = sqlite3.connect('/tmp/sqlite.db')cur = conn.cursor() 接下来干嘛呢?建一张表吧.这里需要注意的 ...

  8. group by 分组去重查询

    数据库中的数据是这样的: 想要看看有几种类型,可以用group by: select * from activiti.act_ru_task where PROC_INST_ID_ in (selec ...

  9. PyTorch Tutorials 5 数据并行(选读)

    %matplotlib inline 数据并行(选读) Authors: Sung Kim and Jenny Kang 在这个教程里,我们将学习如何使用 DataParallel 来使用多GPU. ...

  10. [IMX6DL] CPU频率调节模式以及降频方法

    本文转自http://blog.csdn.net/kris_fei/article/details/51822435 Kernel branch: 3.0.35 CPU的频率调节模式:1. Perfo ...