windows遍历文件夹
来源:互联网 发布:网络代理地址 编辑:程序博客网 时间:2024/05/17 04:04
#include <windows.h>
#include <stdio.h>
typedef BOOL (WINAPI *EnumerateFunc) (LPCSTR lpFileOrPath, void* pUserData);
void doFileEnumeration(LPSTR lpPath, BOOL bRecursion, BOOL bEnumFiles, EnumerateFunc pFunc, void* pUserData)
{
static BOOL s_bUserBreak = FALSE;
try{
//-------------------------------------------------------------------------
if(s_bUserBreak) return;
int len = strlen(lpPath);
if(lpPath==NULL || len<=0) return;
//NotifySys(NRS_DO_EVENTS, 0,0);
char path[MAX_PATH];
strcpy(path, lpPath);
if(lpPath[len-1] != '\\') strcat(path, "\\");
strcat(path, "360*");
WIN32_FIND_DATA fd;
HANDLE hFindFile = FindFirstFile(path, &fd);
if(hFindFile == INVALID_HANDLE_VALUE)
{
::FindClose(hFindFile); return;
}
char tempPath[MAX_PATH]; BOOL bUserReture=TRUE; BOOL bIsDirectory;
BOOL bFinish = FALSE;
while(!bFinish)
{
strcpy(tempPath, lpPath);
if(lpPath[len-1] != '\\') strcat(tempPath, "\\");
strcat(tempPath, fd.cFileName);
bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
//如果是.或..
if( bIsDirectory
&& (strcmp(fd.cFileName, ".")==0 || strcmp(fd.cFileName, "..")==0))
{
bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
continue;
}
if(pFunc && bEnumFiles!=bIsDirectory)
{
bUserReture = pFunc(tempPath, pUserData);
if(bUserReture==FALSE)
{
s_bUserBreak = TRUE; ::FindClose(hFindFile); return;
}
}
//NotifySys(NRS_DO_EVENTS, 0,0);
if(bIsDirectory && bRecursion) //是子目录
{
doFileEnumeration(tempPath, bRecursion, bEnumFiles, pFunc, pUserData);
}
bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
}
::FindClose(hFindFile);
//-------------------------------------------------------------------------
}catch(...){ return; }
}
BOOL WINAPI myEnumerateFunc(LPCSTR lpFileOrPath, void* pUserData)
{
//char* pdot;
//if((pdot = strrchr(lpFileOrPath, '.')) && stricmp(pdot, ".mp3") == 0)
//{
printf("%s\n", lpFileOrPath);
//}
return TRUE;
}
int main()
{
doFileEnumeration("E:\\360Chrome\\Chrome\\User Data\\Default", TRUE, TRUE, myEnumerateFunc, NULL);
return 0;
}
#include <stdio.h>
typedef BOOL (WINAPI *EnumerateFunc) (LPCSTR lpFileOrPath, void* pUserData);
void doFileEnumeration(LPSTR lpPath, BOOL bRecursion, BOOL bEnumFiles, EnumerateFunc pFunc, void* pUserData)
{
static BOOL s_bUserBreak = FALSE;
try{
//-------------------------------------------------------------------------
if(s_bUserBreak) return;
int len = strlen(lpPath);
if(lpPath==NULL || len<=0) return;
//NotifySys(NRS_DO_EVENTS, 0,0);
char path[MAX_PATH];
strcpy(path, lpPath);
if(lpPath[len-1] != '\\') strcat(path, "\\");
strcat(path, "360*");
WIN32_FIND_DATA fd;
HANDLE hFindFile = FindFirstFile(path, &fd);
if(hFindFile == INVALID_HANDLE_VALUE)
{
::FindClose(hFindFile); return;
}
char tempPath[MAX_PATH]; BOOL bUserReture=TRUE; BOOL bIsDirectory;
BOOL bFinish = FALSE;
while(!bFinish)
{
strcpy(tempPath, lpPath);
if(lpPath[len-1] != '\\') strcat(tempPath, "\\");
strcat(tempPath, fd.cFileName);
bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
//如果是.或..
if( bIsDirectory
&& (strcmp(fd.cFileName, ".")==0 || strcmp(fd.cFileName, "..")==0))
{
bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
continue;
}
if(pFunc && bEnumFiles!=bIsDirectory)
{
bUserReture = pFunc(tempPath, pUserData);
if(bUserReture==FALSE)
{
s_bUserBreak = TRUE; ::FindClose(hFindFile); return;
}
}
//NotifySys(NRS_DO_EVENTS, 0,0);
if(bIsDirectory && bRecursion) //是子目录
{
doFileEnumeration(tempPath, bRecursion, bEnumFiles, pFunc, pUserData);
}
bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
}
::FindClose(hFindFile);
//-------------------------------------------------------------------------
}catch(...){ return; }
}
BOOL WINAPI myEnumerateFunc(LPCSTR lpFileOrPath, void* pUserData)
{
//char* pdot;
//if((pdot = strrchr(lpFileOrPath, '.')) && stricmp(pdot, ".mp3") == 0)
//{
printf("%s\n", lpFileOrPath);
//}
return TRUE;
}
int main()
{
doFileEnumeration("E:\\360Chrome\\Chrome\\User Data\\Default", TRUE, TRUE, myEnumerateFunc, NULL);
return 0;
}
0 0
- 遍历文件夹windows
- windows遍历文件夹
- windows下文件夹遍历
- windows遍历文件夹代码
- windows 遍历文件夹
- windows编程之文件夹遍历
- Windows平台 C++遍历文件夹
- c++ windows文件夹的遍历
- Windows遍历指定文件夹及统计信息
- C Windows 读取文件夹 遍历文件
- windows中遍历指定文件夹下的所有子文件夹
- Windows 遍历文件夹下所有文件和文件夹
- windows中遍历指定文件夹下的所有子文件夹
- windows 遍历文件夹及子文件夹的所有
- windows中遍历指定文件夹下的所有子文件夹
- 遍历文件夹
- 遍历文件夹
- 遍历文件夹
- Edit Distance 计算两个字符串的变化距离 动态规划
- Android错误之--Platform MNC is a preview and requires application manifest to set minSdkVersion to 'M
- 关于子进程继承父进程属性的小问题总结
- eclipse构建maven的web项目
- 你不知道java问题if后面加不加括号的问题
- windows遍历文件夹
- Linux环境Nginx安装与调试以及PHP安装
- HDU 1097 A hard puzzle(简单快速幂)
- C# String与string的区别 以及 C# Swap string
- Linux写时拷贝技术(copy-on-write)
- 30多个iOS常用动画,带详细注释
- CocoStudio:ImageView分析
- 链表倒序输出三种算法
- bootstrap单击导航条下的li后,自动收回