The program displays a list of files and folders from a given directory. How to implement alphabetical sorting? When displaying a list.

int main() { WIN32_FIND_DATAW wfd; HANDLE const hFind = FindFirstFileW(L"D:\\Учебка\\*", &wfd); setlocale(LC_ALL, ""); if (INVALID_HANDLE_VALUE != hFind) { do { std::wcout << &wfd.cFileName[0] << std::endl; } while (NULL != FindNextFileW(hFind, &wfd)); FindClose(hFind); } system("pause"); return 0; } 
  • 3
    Get all, sort, then display. It seems like the obvious solution ... - Akina

1 answer 1

The system calls FindFirstFile () / FindNextFile () provide a list of items that fit the search criteria in an undefined order (which may be different for different file systems).

Therefore, the only option is to get the entire list of files (for example, read into memory) and then sort it according to the required criteria.