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

最新文章

  1. c# 利用 两个TREEVIEW控件完成TEENODE的鼠标拖动操作
  2. Linux中的文件描述符与打开文件之间的关系
  3. HDU 2602 Find a way BFS搜索
  4. Objective-C 编程艺术 (Zen and the Art of the Objective-C Craftsmanship 中文翻译)
  5. 桶排序之python实现源码
  6. JVM Monitoring: JMX or SNMP?
  7. [置顶] SSO单点登录系列6:cas单点登录防止登出退出后刷新后退ticket失效报500错
  8. HDU 5974 数学
  9. 操作系统--进程管理1--单个CPU情况
  10. 设置vs环境
  11. 关系型数据库工作原理-查询优化器(翻译自Coding-Geek文章)
  12. CodeForces 1151C Problem for Nazar
  13. Linux之文本编辑器Vim
  14. 第一天 Requests库入门
  15. 来测试下你的Java编程能力
  16. 使用git将项目上传到github(最简单方法)
  17. cf348D. Turtles(LGV定理 dp)
  18. openresty + lua 3、openresty http 调用
  19. WPF之坑——surface触控失灵之谜
  20. MAX II Device Compatibility with 5.0-V CMOS Devices

热门文章

  1. cdoj1092-韩爷的梦 (字符串hash)【hash】
  2. 洛谷——P1894 [USACO4.2]完美的牛栏The Perfect Stall
  3. 2017四川省赛D题《Dynamic Graph》
  4. [POJ2749]Building roads(2-SAT)
  5. hdu 1024 Max Sum Plus Plus DP
  6. linux基础命令学习 (七)压缩解压
  7. dsh安装指南
  8. Wifi模块的工作原理
  9. POJ2352【树状数组】
  10. JS字符串转base64格式