Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <conio.h>
- #include <stdarg.h>
- #include <Windows.h>
- #define BUFFER_SIZE 2048
- void searchAndPrint(wchar_t* templateStr, wchar_t* currDirStr, int level);
- void print(const wchar_t *format, ...);
- void offset(unsigned num);
- int main() {
- wchar_t buffer[BUFFER_SIZE],
- *currDir = 0;
- size_t tmp;
- DWORD dwLen;
- while (true)
- {
- dwLen = GetCurrentDirectoryW(0, currDir);
- currDir = new wchar_t[dwLen];
- GetCurrentDirectoryW(dwLen, currDir);
- print(L"Текущая директория: %s\n", currDir);
- print(L"Введите шаблон для поиска (\\quit для выхода): ");
- _cgetws_s(buffer, &tmp);
- if (wcscmp(buffer, L"\\quit") == 0)
- break;
- searchAndPrint(buffer, L".\\", 0);
- }
- system("pause");
- delete currDir;
- return 0;
- }
- void searchAndPrint(wchar_t* templateStr, wchar_t* currDirStr, int level)
- {
- wchar_t *oldCurrDir = 0;
- WIN32_FIND_DATA ffd;
- DWORD dwLen = GetCurrentDirectoryW(0, oldCurrDir);
- oldCurrDir = new wchar_t[dwLen];
- GetCurrentDirectoryW(dwLen, oldCurrDir);
- SetCurrentDirectory(currDirStr);
- HANDLE hSearch = FindFirstFile(templateStr, &ffd);
- offset(level);
- print(L"<DIR>%s\n", currDirStr);
- if (hSearch != INVALID_HANDLE_VALUE)
- {
- do
- {
- offset(level + 1);
- print(L"%s\n", ffd.cFileName);
- } while (FindNextFile(hSearch, &ffd));
- }
- FindClose(hSearch);
- hSearch = FindFirstFile(L"?*", &ffd);
- if (hSearch != INVALID_HANDLE_VALUE)
- {
- do
- {
- if (!(wcscmp(ffd.cFileName, L"..") == 0 ||
- wcscmp(ffd.cFileName, L".") == 0) &&
- ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- searchAndPrint(templateStr, ffd.cFileName, level + 1);
- }
- } while (FindNextFile(hSearch, &ffd));
- }
- FindClose(hSearch);
- SetCurrentDirectory(oldCurrDir);
- }
- void offset(unsigned num)
- {
- for (unsigned i = 0; i < num; i++)
- printf("--");
- printf("- ");
- }
- void print(const wchar_t *format, ...)
- {
- wchar_t buffer[2048];
- va_list args;
- va_start(args, format);
- wvsprintfW(buffer, format, args);
- _cputws(buffer);
- va_end(args);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement