想遍历一个文件夹,20分买代码。 先来先卖。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // 删除目录void DeleteDirectory(CString strDir){ if(strDir.IsEmpty()) { RemoveDirectory(strDir); return; } // 首先删除文件及子文件夹 CFileFind ff; BOOL bFound = ff.FindFile(strDir+"\\*", 0); while(bFound) { bFound = ff.FindNextFile(); if(ff.GetFileName()=="."||ff.GetFileName()=="..") continue; // 去掉文件(夹)只读等属性 SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL); if(ff.IsDirectory()) { // 递归删除子文件夹 DeleteDirectory(ff.GetFilePath()); RemoveDirectory(ff.GetFilePath()); } else { DeleteFile(ff.GetFilePath()); // 删除文件 } } ff.Close(); // 然后删除该文件夹 RemoveDirectory(strDir);} WIN32_FIND_DATA FindFileData; HANDLE hFind; char szFind[MAX_PATH]; char szTempDir[MAX_PATH]; sprintf(szFind,"%s\\*.*",lpPathName); hFind = FindFirstFile(szFind, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { FindClose(hFind); return FALSE; } do { if (strcmp(FindFileData.cFileName,".")==0 || strcmp(FindFileData.cFileName,"..")==0) { continue; } sprintf(szTempDir,"%s\\%s",lpPathName,FindFileData.cFileName); } while(FindNextFile(hFind,&FindFileData)); FindClose(hFind); void Exp(const char * name);int main(int argc, char* argv[]){ Exp("c:\\windows"); return 0;}void Exp(const char * name){ if(!name) { return ; } if(!strlen(name)) { return ; } char szBuf[MAX_PATH] = {0}; strcpy(szBuf , name); if(szBuf[strlen(szBuf) - 1] != '\\') { strcat(szBuf , "\\"); } strcat(szBuf , "*.*"); WIN32_FIND_DATA fd; memset(&fd , 0 , sizeof(fd)); BOOL bFind = TRUE; HANDLE hFind = FindFirstFile(szBuf , &fd); while(bFind) { if(strcmp(fd.cFileName , ".") == 0) { bFind = FindNextFile(hFind , &fd); continue; } else if(strcmp(fd.cFileName , "..") == 0) { bFind = FindNextFile(hFind , &fd); continue; } else if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { char szPath[MAX_PATH] = {0}; strcpy(szPath , szBuf); *strrchr(szPath , '\\') = '\0'; strcat(szPath , "\\"); strcat(szPath , fd.cFileName); Exp(szPath); } else { char szPath[MAX_PATH] = {0}; strcpy(szPath , szBuf); *strrchr(szPath , '\\') = '\0'; strcat(szPath , "\\"); strcat(szPath , fd.cFileName); printf("%s\n" , szPath); } bFind = FindNextFile(hFind , &fd); } CloseFind(hFind); return ;} 关于一个树视图的问题~ 寻找防止DLL注入的方法? 滚动条咋了 多线程得问题,看了几个MFC的同步对象,感觉都不能达到目的,百思不得其解!达人帮忙!!! wav api录音程序的链接错误,在线等待。谢谢。 一个很苦恼的问题,怎样使用服务器程序自动发送数据----高分奉送 有关内联函数的问题?? 无线安全 window 编译 aircrack-ng-1.0? VC中如何点击弹出对话框按钮实现向单文档OnPaint()中传递一个函数 请教 API文件夹长度的限制如何解决 又是一个数据转化问题! 工具条问题 100分等待
void DeleteDirectory(CString strDir)
{
if(strDir.IsEmpty()) {
RemoveDirectory(strDir);
return;
}
// 首先删除文件及子文件夹
CFileFind ff;
BOOL bFound = ff.FindFile(strDir+"\\*", 0);
while(bFound)
{
bFound = ff.FindNextFile();
if(ff.GetFileName()=="."||ff.GetFileName()=="..")
continue;
// 去掉文件(夹)只读等属性
SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
if(ff.IsDirectory()) { // 递归删除子文件夹
DeleteDirectory(ff.GetFilePath());
RemoveDirectory(ff.GetFilePath());
}
else {
DeleteFile(ff.GetFilePath()); // 删除文件
}
}
ff.Close();
// 然后删除该文件夹
RemoveDirectory(strDir);
}
HANDLE hFind;
char szFind[MAX_PATH];
char szTempDir[MAX_PATH]; sprintf(szFind,"%s\\*.*",lpPathName);
hFind = FindFirstFile(szFind, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return FALSE;
}
do
{
if (strcmp(FindFileData.cFileName,".")==0
|| strcmp(FindFileData.cFileName,"..")==0)
{
continue;
}
sprintf(szTempDir,"%s\\%s",lpPathName,FindFileData.cFileName);
}
while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
{
Exp("c:\\windows");
return 0;
}
void Exp(const char * name)
{
if(!name)
{
return ;
}
if(!strlen(name))
{
return ;
} char szBuf[MAX_PATH] = {0};
strcpy(szBuf , name);
if(szBuf[strlen(szBuf) - 1] != '\\')
{
strcat(szBuf , "\\");
} strcat(szBuf , "*.*"); WIN32_FIND_DATA fd;
memset(&fd , 0 , sizeof(fd)); BOOL bFind = TRUE;
HANDLE hFind = FindFirstFile(szBuf , &fd);
while(bFind)
{
if(strcmp(fd.cFileName , ".") == 0)
{
bFind = FindNextFile(hFind , &fd);
continue;
}
else if(strcmp(fd.cFileName , "..") == 0)
{
bFind = FindNextFile(hFind , &fd);
continue;
}
else if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char szPath[MAX_PATH] = {0};
strcpy(szPath , szBuf);
*strrchr(szPath , '\\') = '\0';
strcat(szPath , "\\");
strcat(szPath , fd.cFileName);
Exp(szPath);
}
else
{
char szPath[MAX_PATH] = {0};
strcpy(szPath , szBuf);
*strrchr(szPath , '\\') = '\0';
strcat(szPath , "\\");
strcat(szPath , fd.cFileName);
printf("%s\n" , szPath);
}
bFind = FindNextFile(hFind , &fd);
} CloseFind(hFind);
return ;
}