// FindFileDebug.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include "FindFileDebug.h" #ifdef _DEBUG
#define new DEBUG_NEW
#endif #define IS_DIRECTORY(x) ((x) & (FILE_ATTRIBUTE_DIRECTORY))
#define IS_FAILED (0) void TraversFile(CString csPath, CString & csDatabuffer);
BOOL IsDot(LPCTSTR ptStr);
using namespace std; #define TESTPATH ("G:\\Python脚本\\PyCahrm项目") int main()
{
int nRetCode = ;
CString filepath = CString(TESTPATH);
CString FileBuffer;
TraversFile(filepath, FileBuffer);
printf("错误: GetModuleHandle 失败\n");
system("pause");
return nRetCode;
} void TraversFile(CString csPath, CString & csDatabuffer)
{
CString csPrePath = csPath;
CString csNextPath = csPath;
CString csNextLine = CString("\r\n");
CString csSlash = CString("\\"); WIN32_FIND_DATA FindFileData = { };
HANDLE hFistFind = FindFirstFile(csPath + CString("\\*.*"), (LPWIN32_FIND_DATA)&FindFileData);
if ( INVALID_HANDLE_VALUE == hFistFind)
{
printf("Failed to open file" );
}
else
{
wcout << FindFileData.cFileName;
}
do {
if (IsDot(FindFileData.cFileName))
{
continue;
}
if (IS_DIRECTORY(FindFileData.dwFileAttributes))
{
csNextPath += "\\";
csNextPath += FindFileData.cFileName;
TraversFile(csNextPath, csDatabuffer);
csNextPath = csPrePath;
}
else
{
csDatabuffer += csNextPath + csSlash + FindFileData.cFileName + csNextLine;
wcout << FindFileData.cFileName;
}
} while (FindNextFile(hFistFind, (LPWIN32_FIND_DATA)&FindFileData) != IS_FAILED);
FindClose(hFistFind);
hFistFind = INVALID_HANDLE_VALUE;
} BOOL IsDot(LPCTSTR ptStr)
{
size_t ulen = wcslen (ptStr);
if (ulen >= )
{
return TRUE;
}
while (ulen--)
{
if (ptStr[ulen] != L'.')
{
return FALSE;
}
}
return TRUE;
}

已适配的DLL源文件

 // FileFunction20190101Dll.cpp : 定义 DLL 应用程序的导出函数。
// #include "stdafx.h"
#include "string"
#define IS_DIRECTORY(x) ((x) & (FILE_ATTRIBUTE_DIRECTORY))
#define IS_FAILED (0) using namespace std; string g_csBuffer; extern "C"
{
BOOL IsDot(LPCSTR ptStr)
{
size_t ulen = strlen(ptStr);
if (ulen >= )
{
return TRUE;
}
while (ulen--)
{
if (ptStr[ulen] != '.')
{
return FALSE;
}
}
return TRUE;
}
}
extern "C" // 此处extern "c" 为解决c/c++兼容问题
{
_declspec(dllexport)void TraversFile(string csPath, string & csDatabuffer)
{
string csPrePath = csPath;
string csNextPath = csPath;
string csNextLine = string("\r\n");
string csSlash = string("\\"); WIN32_FIND_DATAA FindFileData = { };
HANDLE hFistFind = FindFirstFileA((csPath + string("\\*.*")).c_str(), (LPWIN32_FIND_DATAA)&FindFileData);
if (INVALID_HANDLE_VALUE == hFistFind)
{
printf("Failed to open file:%s,%s", csPath.c_str(), string("\\*.*").c_str());
return;
}
do {
if (IsDot(FindFileData.cFileName))
{
continue;
}
if (IS_DIRECTORY(FindFileData.dwFileAttributes))
{
csNextPath += "\\";
csNextPath += FindFileData.cFileName;
TraversFile(csNextPath, csDatabuffer);
csNextPath = csPrePath;
}
else
{
csDatabuffer += csNextPath + csSlash + FindFileData.cFileName + csNextLine;
}
} while (FindNextFileA(hFistFind, (LPWIN32_FIND_DATAA)&FindFileData) != IS_FAILED);
FindClose(hFistFind);
hFistFind = INVALID_HANDLE_VALUE;
}
} extern "C"
{
_declspec(dllexport)LPCSTR TraversFileInterface(char * pFilePath, int * pLength)
{
if (!g_csBuffer.empty())
{
g_csBuffer.clear();
}
string csPath = string(pFilePath);
TraversFile(csPath, g_csBuffer);
*pLength = g_csBuffer.length(); return g_csBuffer.c_str();
}
} extern "C"
{
_declspec(dllexport)unsigned int TraversFileInterfaceRelease()
{
g_csBuffer.clear();
return ;
}
} extern "C"
{
_declspec(dllexport)unsigned int PrintHex(unsigned char * pData, unsigned int length)
{
for (unsigned int unloop = ; unloop < length; ++unloop)
{
printf("%02x ", pData[unloop]);
}
return ;
}
}

API的文件遍历,未使用CFileFind,因为里面牵扯MFC,编个DLL好麻烦。的更多相关文章

  1. 使用 JavaScript File API 实现文件上传

    概述 以往对于基于浏览器的应用而言,访问本地文件都是一件头疼的事情.虽然伴随着 Web 2.0 应用技术的不断发展,JavaScript 正在扮演越来越重要的角色,但是出于安全性的考虑,JavaScr ...

  2. HTML5的File API读取文件信息

    html结构: <div id="fileImage"></div> <input type="file" value=" ...

  3. Web API与文件操作

    前段时间,一直有练习ASP.NET MVC与Web API交互,接下来,Insus.NET再做一些相关的练习,Web API与文件操作,如POST文件至Web API,更新或是删除等. 不管怎样,先在 ...

  4. 生成的API分析文件太大。我们无法在交付前验证您的API使用信息。这只是通知信息。

    这次使用了APICloud平台来开发移动APP, 发布的时候在api控制台云编译成ipa后,这次使用apple提供的Application Loader工具提交apa文件到iTunes上去,提交结束的 ...

  5. Resumable.js – 基于 HTML5 File API 的文件上传

    Resumable.js 是一个 JavaScript 库,通过 HTML5 文件 API 提供,稳定和可恢复的批量上传功能.在上传大文件的时候通过每个文件分割成小块,每块在上传失败的时候,上传会不断 ...

  6. HTML5 file api读取文件的MD5码工具

    1.工具的用途:用HTML5 file api读取文件的MD5码.MD5码在文件的唯一性识别上有很重要的应用,业内常用MD5进行文件识别.文件秒传.文件安全性检查等: 2.适用性:IE.Chrome皆 ...

  7. git clean 删除忽略文件 和 未被跟踪文件及文件夹

    git clean 删除忽略文件 和 未被跟踪文件及文件夹 概念 首先我们需要认清 忽略的文件 和 未被跟踪的文件 忽略的文件:.gitignore 中忽略的文件 未被跟踪的文件:没有被忽略,但是还没 ...

  8. Python os.walk文件遍历用法【转】

    python中os.walk是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 1.载入 要使用os.walk,首先要载入该函数 可以使用以下两种方法 import os ...

  9. Python文件遍历二种方法

    分享下有关Python文件遍历的两种方法,使用的OS模块的os.walk和os.listdir实现. 关于Python的文件遍历,大概有两种方法,一种是较为便利的os.walk(),还有一种是利用os ...

随机推荐

  1. Arduino可穿戴教程之第一个程序——选择端口(三)

    Arduino可穿戴教程之第一个程序——选择端口(三) 2.4.4  选择端口 在选择了板子之后,我们就需要选择板子连接到电脑的端口了.它也在“工具”菜单中设置,如图2.42所示. 注意:COM1端口 ...

  2. 数据仓库之父——Bill Inmon(转载)

    从此处转载 http://blog.sina.com.cn/s/blog_615f9dba0100f67p.html 比尔·恩门(Bill Inmon),被称为数据仓库之父,最早的数据仓库概念提出者, ...

  3. App图标生成器的实现,附源码

    背景 网上各种生成app图标的网站和工具,感觉还是用自己写的心里畅快点,所以花了1个小时自己写了个.按照网上给的图标尺寸规范把所有尺寸的都生成了. 建了一个讨论群,533838427.很明显是针对独立 ...

  4. 【8.19校内测试】【背包】【卡特兰数】【数位dp】

    早上随便搞搞t1t3就开始划水了,t2一看就是组合数学看着肚子疼...结果t1t3都a了??感天动地. 从小到大排序,从前到后枚举i,表示i是整个背包中不选的物品中代价最小的那个,即i不选,1到i-1 ...

  5. bzoj 2055: 80人环游世界 -- 上下界网络流

    2055: 80人环游世界 Time Limit: 10 Sec  Memory Limit: 64 MB Description     想必大家都看过成龙大哥的<80天环游世界>,里面 ...

  6. 05-树6. Path in a Heap (25) 小根堆

    05-树6. Path in a Heap (25) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.patest.cn/contes ...

  7. Android/Java 中的 String, StringBuffer, StringBuilder的区别和使用

    Android 中的 String, StringBuffer 和 StringBuilder 是移动手机开发中经常使用到的字符串类.做为基础知识是必须要理解的,这里做一些总结. A.区别 可以从以下 ...

  8. 如何终止JQUERY的$.AJAX请求

    最近遇到,如果用户频繁点击ajax请求,有两个问题: 1,如果连续点击了5个ajax请求,前4个其实是无效的,趁早结束节省资源. 2,更严重的问题是:最后一个发送的请求,响应未必是最后一个,有可能造成 ...

  9. CentOS 6.9/7安装Parse+PostgreSQL

    一.安装Parse-Server # npm install -g parse-server --unsafe-perm 备注:用--unsafe-perm参数的目的是使用了root权限进行安装. 二 ...

  10. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...