int DeviceConfig::GetFolderCount(CString target_folder)
{
int count = -1; //檔案的counter
TCHAR szDir[128]; //要讀取的資料夾的位址。
WIN32_FIND_DATA FileData; //指著目前讀取到的File的指標。
HANDLE hList; //指著要讀取的資料夾的指標。
_stprintf_s(szDir, _T("%ws\\*"), target_folder);
if ((hList = FindFirstFile((LPCWSTR)szDir, &FileData)) == INVALID_HANDLE_VALUE)
cout << "No directories be found." << endl << endl;
else {
while (1) {
if (!FindNextFile(hList, &FileData)) {
if (GetLastError() == ERROR_NO_MORE_FILES)
break;
}
count++;
}
}
FindClose(hList);
return count;
}