Advertisement
mrAnderson33

аналог dir

May 31st, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. _TCHAR * SystemTimeToTchar(SYSTEMTIME);
  4. _TCHAR * FileSizeToTchar(DWORD);
  5.  
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     WIN32_FIND_DATAW wfd;
  9.     SYSTEMTIME time;
  10.  
  11.     if (argc >1)
  12.     {
  13.         for (int i = 1; i < argc ; ++i)
  14.         {
  15.             HANDLE const hFind = FindFirstFileW(argv[i], &wfd);
  16.             setlocale(LC_ALL, "");
  17.  
  18.             wprintf(L"Contents of directory %s :\n\n",argv[i]);
  19.  
  20.             if (INVALID_HANDLE_VALUE != hFind)
  21.             {
  22.                 do
  23.                 {
  24.                     _TCHAR type[6]=L"     ";
  25.                     _TCHAR size[20] = L"         ";
  26.                     if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )wsprintf(type, L"<DIR>");
  27.                     else wsprintf(size,L"%d",wfd.nFileSizeLow);
  28.                     FileTimeToSystemTime(&wfd.ftLastWriteTime, &time);
  29.                     wprintf(L"%s     %s %s    %s\n", SystemTimeToTchar(time), type, size , &wfd.cFileName[0]);
  30.                     wprintf(L"%s\n",size);
  31.  
  32.                 } while (NULL != FindNextFileW(hFind, &wfd));
  33.  
  34.                 FindClose(hFind);
  35.             }
  36.         }
  37.     }
  38.     else std::cout << "Please, enter directory!\n";
  39.    
  40.     return 0;
  41. }
  42.  
  43. _TCHAR * SystemTimeToTchar(SYSTEMTIME time)
  44. {
  45.     _TCHAR str[256];
  46.     _TCHAR  second[3];
  47.     _TCHAR  minute[3];
  48.     _TCHAR  hour[3];
  49.     _TCHAR  day[3];
  50.     _TCHAR  month[3];
  51.     wsprintf(second, time.wSecond >9 ? L"%d" : L"0%d", time.wSecond);
  52.     wsprintf(minute, time.wMinute >9 ? L"%d" : L"0%d", time.wMinute);
  53.     wsprintf(hour, time.wHour >9 ? L"%d" : L"0%d", time.wHour);
  54.     wsprintf(day, time.wDay >9 ? L"%d" : L"0%d", time.wDay);
  55.     wsprintf(month , time.wMonth >9 ? L"%d" : L"0%d", time.wMonth);
  56.  
  57.     wsprintf(str, L"%s.%s.%d %s:%s", day,month, time.wYear,hour,minute,second);
  58.  
  59.     return str;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement