VC++ 遍历文件夹
1 char szFind[MAX_PATH] = {0}; 2 strcpy_s(szFind, MAX_PATH, m_szDir); 3 strcat_s(szFind, "\\*.*"); 4 5 WIN32_FIND_DATA wfd; 6 HANDLE hFind = ::FindFirstFile(MultiByteToWideChar(szFind), &wfd); 7 if (INVALID_HANDLE_VALUE != hFind) 8 { 9 while (TRUE) 10 { 11 if (wfd.cFileName[0] != _T('.'))// 不是当前目录或者父目录 12 { 13 printf("...\n"); 14 } 15 if (!::FindNextFile(hFind, &wfd)) break; 16 } 17 } 18 19 FindClose(hFind);
其中MultiByteToWideChar(char*)函数是用来将char数组转化成wchar_t字符串的。
1 wchar_t* MultiByteToWideChar(char* ch) 2 { 3 int num = MultiByteToWideChar(0,0,ch,-1,NULL,0); 4 wchar_t *wide = new wchar_t[num]; 5 MultiByteToWideChar(0,0,ch,-1,wide,num); 6 return wide; 7 }