文件夹的遍历
真是会什么来什么 前段时间才看到深搜 今天看王艳平那本 《windows程序设计》 第三章的列子 多线程实现一个文件搜索器
打算自己先写一个 能达到目的就行
1 #include <stdio.h> 2 #include <windows.h> 3 #include <stack> 4 #include <string> 5 6 7 using namespace std; 8 9 10 int main(int argc, char * argv[]) 11 { 12 string strCuurPath = "e:\\program Files\\11\\"; 13 stack<string> vectStr; 14 vectStr.push(strCuurPath); 15 16 WIN32_FIND_DATA findData; 17 HANDLE hFindFile; 18 19 while(!vectStr.empty()) 20 { 21 strCuurPath = vectStr.top(); 22 vectStr.pop(); 23 string strNeedFind = strCuurPath +"*.*"; 24 hFindFile = FindFirstFile(strNeedFind.c_str(), &findData); 25 if( hFindFile != INVALID_HANDLE_VALUE) 26 { 27 do 28 { 29 if(findData.cFileName[0] == '.') continue; 30 if(findData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY) 31 { 32 strNeedFind = strCuurPath + findData.cFileName + "\\"; 33 vectStr.push(strNeedFind); 34 printf("%s \n", strNeedFind.c_str()); 35 } 36 }while(FindNextFile(hFindFile, &findData)); 37 FindClose(hFindFile); 38 } 39 40 } 41 42 return 0; 43 }