// 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. Java变量和运算符

    1.变量 变量概述 什么是变量?变量是一个内存中的小盒子(小容器),容器是什么?生活中也有很多容器,例如水杯是容器,用来装载水:你家里的大衣柜是容器,用来装载衣裤:饭盒是容器,用来装载饭菜.那么变量是 ...

  2. 将 Unity5.3 的老项目升级到 Unity 2018.3 遇到的些许问题。

    删除 ParticleEmmiter 等废弃的接口: 删除 WindowsSecurityContext System.Security.Principal.WindowsIdentity 在 .Ne ...

  3. 【转】全面了解Mysql中的事务

    为什么要有事务? 事务广泛的运用于订单系统.银行系统等多种场景.如果有以下一个场景:A用户和B用户是银行的储户.现在A要给B转账500元.那么需要做以下几件事: 1. 检查A的账户余额>500元 ...

  4. POJ2955【区间DP】

    题目链接[http://poj.org/problem?id=2955] 题意:[].()的匹配问题,问一个[]()串中匹配的字符数,匹配方式为[X],(X),X为一个串,问一个长度为N(N<= ...

  5. [BZOJ4032][HEOI2015]最短不公共子串(Trie+DP)

    在虐各种最长公共子串.子序列的题虐的不耐烦了之后,你决定反其道而行之——被它们虐. 操作一:对A,B分别建SAM,暴力BFS. 操作二:对B建序列自动机或SAM,A在上面暴力匹配. 操作三:对A,B建 ...

  6. [转]Android网格视图(GridView)

    GridView的一些属性: 1.android:numColumns=”auto_fit”   //GridView的列数设置为自动,也可以设置成2.3.4…… 2.android:columnWi ...

  7. MC34063组成DC-DC电路

    +VO的输出电压峰值可达2倍V_IN,-VO的输出电压可达-V_IN. 需要注意的是,3路的峰值电路不能超过1.5A,同时两路附加电源的输出功率和必须小于V_IN·I·(1-D), 其中I为主输出的电 ...

  8. Using an open debug interconnect model to simplify embedded systems design

    Using an open debug interconnect model to simplify embedded systems design Tom Cunningham, Freescale ...

  9. chm TO html 另类方法

    因为网上下了很多chmtohtml ,都是试用版的, 转成html网页格式,总是有限制,或是不完整,我现在找到了一种折中方法,供大家参考 一,我的资源里有工具word to chm  里面有转成网页的 ...

  10. 富文本编辑器、日期选择器、软件天堂、防止XSS攻击、字体icon、转pdf

    [超好用的日期选择器] Layui:http://www.layui.com/laydate/ 备注:日期选择器,用过很多很多,自己也写过一些:相信这个简单而又不简单的选择器,能够给你多些美好的时光 ...