API的文件遍历,未使用CFileFind,因为里面牵扯MFC,编个DLL好麻烦。
// 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好麻烦。的更多相关文章
- 使用 JavaScript File API 实现文件上传
概述 以往对于基于浏览器的应用而言,访问本地文件都是一件头疼的事情.虽然伴随着 Web 2.0 应用技术的不断发展,JavaScript 正在扮演越来越重要的角色,但是出于安全性的考虑,JavaScr ...
- HTML5的File API读取文件信息
html结构: <div id="fileImage"></div> <input type="file" value=" ...
- Web API与文件操作
前段时间,一直有练习ASP.NET MVC与Web API交互,接下来,Insus.NET再做一些相关的练习,Web API与文件操作,如POST文件至Web API,更新或是删除等. 不管怎样,先在 ...
- 生成的API分析文件太大。我们无法在交付前验证您的API使用信息。这只是通知信息。
这次使用了APICloud平台来开发移动APP, 发布的时候在api控制台云编译成ipa后,这次使用apple提供的Application Loader工具提交apa文件到iTunes上去,提交结束的 ...
- Resumable.js – 基于 HTML5 File API 的文件上传
Resumable.js 是一个 JavaScript 库,通过 HTML5 文件 API 提供,稳定和可恢复的批量上传功能.在上传大文件的时候通过每个文件分割成小块,每块在上传失败的时候,上传会不断 ...
- HTML5 file api读取文件的MD5码工具
1.工具的用途:用HTML5 file api读取文件的MD5码.MD5码在文件的唯一性识别上有很重要的应用,业内常用MD5进行文件识别.文件秒传.文件安全性检查等: 2.适用性:IE.Chrome皆 ...
- git clean 删除忽略文件 和 未被跟踪文件及文件夹
git clean 删除忽略文件 和 未被跟踪文件及文件夹 概念 首先我们需要认清 忽略的文件 和 未被跟踪的文件 忽略的文件:.gitignore 中忽略的文件 未被跟踪的文件:没有被忽略,但是还没 ...
- Python os.walk文件遍历用法【转】
python中os.walk是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 1.载入 要使用os.walk,首先要载入该函数 可以使用以下两种方法 import os ...
- Python文件遍历二种方法
分享下有关Python文件遍历的两种方法,使用的OS模块的os.walk和os.listdir实现. 关于Python的文件遍历,大概有两种方法,一种是较为便利的os.walk(),还有一种是利用os ...
随机推荐
- Java常用工具类之时间转换(注释乱码,全)
package com.wazn.learn.util; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...
- python计数器Count
python计数器Count # -*- coding:utf-8 -*- """ python计数器Counter 需导入模块collections "&qu ...
- BZOJ [JSOI2008]星球大战starwar
正着显然不可做,我们采取反向并查集,将删点改为加点,每次贪心的认为加了一个联通块,一旦不符就减一. #include<bits/stdc++.h> using namespace std; ...
- HDU1429 胜利大逃亡 状压bfs
http://acm.hdu.edu.cn/viewcode.php?rid=22225154 因为总共a-j有10种钥匙,所以可以把有没有钥匙的状态压到一个int数里,然后dfs. 昨天状态特别不好 ...
- 【8.20校内测试】【DP】【二分+贪心】
一开始想的贪心,可是发现贪心的问题太多了啊!只能保证当前最优,全局完全无法考虑. 所以正解是dp.预处理出前缀和,枚举每个区间,在每个点记录$now[i]$表示以$i$这个塔结尾的塔组目前的高度.$d ...
- 清北学堂学习总结 day2 字符串 练习
1.hash表(哈希表) codevs 2147 数星星--简单哈希 时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小明 ...
- URAL 1997 Those are not the droids you're looking for 二分图最大匹配
Those are not the droids you're looking for 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1 ...
- hihocoder155周 任务分配
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, EN ), 计算最少需要多 ...
- List与ArrayList的区别
http://www.cnblogs.com/aisiteru/articles/1151874.html List是一个接口,而ListArray是一个类. ListArray继承并实现了List. ...
- URAL 1099. Work Scheduling (一般图匹配带花树)
1099. Work Scheduling Time limit: 0.5 secondMemory limit: 64 MB There is certain amount of night gua ...