#define _CRT_SECURE_NO_WARNINGS #include #include void listFilesRecursively(WCHAR* basePath) { WCHAR searchPath[MAX_PATH]; WIN32_FIND_DATA findData; HANDLE hFind; wsprintfW(searchPath, L"%s\\*.*", basePath); hFind = FindFirstFile(searchPath, &findData); if (hFind == INVALID_HANDLE_VALUE) { return; } do { if (wcscmp(findData.cFileName, L".") != 0 && wcscmp(findData.cFileName, L"..") != 0) { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { wsprintfW(searchPath, L"%s\\%s", basePath, findData.cFileName); listFilesRecursively(searchPath); } else { wprintf(L"%s\\%s\n", basePath, findData.cFileName); } } } while (FindNextFile(hFind, &findData) != 0); FindClose(hFind); } int main() { WCHAR basePath[MAX_PATH]; wprintf(L"Enter the path to list files: "); if (wscanf_s(L"%s", basePath, (unsigned)_countof(basePath)) == 1) { listFilesRecursively(basePath); } else { wprintf(L"Error reading input.\n"); } return 0; }