yukisaw

PathFinder

Jul 25th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. //#include <stdafx.h>
  2. #include <windows.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. wchar_t *c_to_w(char *c)
  7. {
  8.     wchar_t *res = new wchar_t(strlen(c));
  9.     mbstowcs(res, c, strlen(c));
  10.     return res;
  11. }
  12.  
  13. char *w_to_c(wchar_t *w)
  14. {
  15.     char *res = new char(wcslen(w));
  16.     wcstombs(res, w, wcslen(w));
  17.     return res;
  18. }
  19.  
  20. int FileSearch(LPWSTR Path = L"C:\\*.") //было бы не плохо автоматически Рабочий стол находить
  21. {
  22. WIN32_FIND_DATA fd;
  23. char *p = w_to_c(Path);
  24. HANDLE hf = FindFirstFile(p, &fd);
  25. delete p;
  26. if (hf != INVALID_HANDLE_VALUE)
  27. {
  28. do
  29. {
  30. LPWSTR dlim = L"\\";
  31. LPWSTR SubPath = c_to_w(fd.cFileName);
  32. wstring df = wstring(Path);
  33. df += dlim;
  34. df+=wstring(SubPath);
  35. LPWSTR DFl = &df[0];
  36. if (fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
  37. {
  38. FileSearch(DFl);
  39. }
  40. else
  41. {
  42. char *buf = w_to_c(DFl);
  43. MessageBox(NULL, buf, "Поиск", MB_OKCANCEL);
  44. delete buf;
  45. }
  46. } while (FindNextFile(hf, &fd) != 0);
  47. FindClose(hf);
  48. }
  49. }
  50.  
  51. int main()
  52. {
  53. FileSearch(L"C:\\*.");
  54. system("pause");
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment