#define _CRT_SECURE_NO_WARNINGS #define _UNICODE #define UNICODE #include #include #include #include #include #include #include #include #include #include #include void printBinary(DWORD num); void printTypeDrive(); void printFileAtrib(); void printFindFileData(); void printSystemPath(); void printTimeFile(); void printSetTimeFile(); void printCreateDirectory(); void printReadFile(); int main(void) { // программа только для UNICODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! const wchar_t str[] = L"help"; const wchar_t str1[] = L"exit"; const wchar_t str2[] = L"typeD"; const wchar_t str3[] = L"printD"; const wchar_t str4[] = L"fileA"; const wchar_t str5[] = L"findF"; const wchar_t str6[] = L"systemD"; const wchar_t str7[] = L"fileTime"; const wchar_t str8[] = L"setFileTime"; const wchar_t str9[] = L"createDirect"; const wchar_t str10[] = L"readFile"; _setmode(_fileno(stdin), _O_U16TEXT); _setmode(_fileno(stdout), _O_U16TEXT); _setmode(_fileno(stderr), _O_U16TEXT); wchar_t comand[50]; //setlocale(LC_ALL, ".UTF8"); _tprintf(_T("Здравствуйте, в связи с атакой террористов на мое воображение эта программа получила название \"Программа\"\n")); while (1) { _tprintf(_T("Введите команду: ")); fgetws(comand,sizeof(comand), stdin); comand[wcslen(comand) - 1] = 0; if(!wcscmp(comand, str)) { _tprintf(_T("Тут должен быть список доступных команд, но его нет - как жаль(\n")); } else if (!wcscmp(comand, str3)) { DWORD uDriveMask = GetLogicalDrives(); printBinary(uDriveMask); } else if (!wcscmp(comand, str4)) { printFileAtrib(); } else if (!wcscmp(comand, str2)) { printTypeDrive(); } else if (!wcscmp(comand, str5)) { printFindFileData(); } else if (!wcscmp(comand, str6)) { printSystemPath(); } else if (!wcscmp(comand, str7)) { printTimeFile(); } else if (!wcscmp(comand, str8)) { printSetTimeFile(); } else if (!wcscmp(comand, str9)) { printCreateDirectory(); } else if (!wcscmp(comand, str10)) { printReadFile(); } else if (!wcscmp(comand, str1)) { _tprintf(_T("Произошел выход из программы!\n")); break; } else { _tprintf(_T("Неверная команда!\n")); } } return 0; } void printFileAtrib() { _tprintf(_T("Введите адрес файла: ")); wchar_t filePath[1024]; fgetws(filePath, sizeof(filePath), stdin); filePath[wcslen(filePath) - 1] = 0; int fileAttributes = GetFileAttributes(filePath); if (fileAttributes == -1) { _tprintf(_T("Ненашел\n")); } else { if (fileAttributes & FILE_ATTRIBUTE_ARCHIVE) { _tprintf(_T("Архивный\n")); } if (fileAttributes & FILE_ATTRIBUTE_COMPRESSED) { _tprintf(_T("Сжатый\n")); } if (fileAttributes & FILE_ATTRIBUTE_READONLY) { _tprintf(_T("Только для чтения\n")); } if (fileAttributes & FILE_ATTRIBUTE_DEVICE) {} } } void printTypeDrive(){ TCHAR driveName[] = _T("C:\\"); _tprintf(_T("Введите букву диска: ")); _tscanf(_T("%c"), driveName); _tprintf(_T("Введённое имя дискa: %s\n"), driveName); UINT type = GetDriveType(driveName); switch (type) { case DRIVE_NO_ROOT_DIR: _tprintf(_T("Диск не найден!!!\n")); break; case DRIVE_REMOVABLE: _tprintf(_T("Этот диск сьемный\n")); break; case DRIVE_FIXED: _tprintf(_T("Фиксированный диск\n")); break; default: break; } } void printBinary(DWORD num) { _tprintf(_T("Доступные диски: ")); for (BYTE i = 0; i < 28; i++) { if (num & 1) { _tprintf(_T("%c"), (_T('A') + i)); // L'A' + i } num >>= 1; } _tprintf(_T("\n")); } void printFindFileData() { _tprintf(_T("Введите адрес файла: ")); WIN32_FIND_DATA findFileData; wchar_t filePath[1024]; fgetws(filePath, sizeof(filePath), stdin); filePath[wcslen(filePath) - 1] = 0; HANDLE hFind = FindFirstFile(filePath, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { _tprintf(_T("Какая-то лажа с путем к файлу")); } else { do { _tprintf(_T("%s\n"), findFileData.cFileName); } while (FindNextFile(hFind, &findFileData)); FindClose(hFind); } } void printSystemPath() { wchar_t system_directory[MAX_PATH]; GetSystemDirectory(system_directory, MAX_PATH); _tprintf(_T("Системная папка: %s\n"), system_directory); } void printTimeFile() { _tprintf(_T("Введите адрес файла: ")); wchar_t filename[1024]; fgetws(filename, sizeof(filename), stdin); filename[wcslen(filename) - 1] = 0; FILETIME date_soz, fileInfo1; SYSTEMTIME systemTime; HANDLE hFile = CreateFile( filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { _tprintf(_T("Не найден файл \n")); } else { GetFileTime(hFile, &date_soz, &fileInfo1, NULL); FileTimeToSystemTime(&date_soz, &systemTime); _tprintf(_T("Дата cоздания файла: %d.%d.%dг %d:%d:%d\n"), systemTime.wDay, systemTime.wMonth, systemTime.wYear, systemTime.wHour + 3, systemTime.wMinute, systemTime.wSecond ); FileTimeToSystemTime(&fileInfo1, &systemTime); _tprintf(_T("Последнее открытие файла: %d.%d.%dг в %d:%d:%d\n"), systemTime.wDay, systemTime.wMonth, systemTime.wYear, systemTime.wHour + 3, systemTime.wMinute, systemTime.wSecond ); } } void printSetTimeFile() { _tprintf(_T("Введите адрес файла: ")); wchar_t filename[1024]; fgetws(filename, sizeof(filename), stdin); filename[wcslen(filename) - 1] = 0; FILETIME date_soz, fileInfo1; SYSTEMTIME systemTime; _tprintf(_T("Введите новую дату создания файла(через Enter): ")); wscanf(L"%d", &systemTime.wYear); wscanf(L"%d", &systemTime.wMonth); wscanf(L"%d", &systemTime.wDay); wscanf(L"%d", &systemTime.wHour); wscanf(L"%d", &systemTime.wMinute); wscanf(L"%d", &systemTime.wSecond); HANDLE hFile = CreateFile( filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { _tprintf(_T("Не найден файл \n")); } else { SystemTimeToFileTime(&systemTime, &date_soz); SetFileTime(hFile, &date_soz, NULL, NULL); _tprintf(_T("Дата cоздания файла: %d.%d.%dг\n"), systemTime.wDay, systemTime.wMonth, systemTime.wYear); /* FileTimeToSystemTime(&fileInfo1, &systemTime); _tprintf(_T("Последнее открытие файла: %d.%d.%dг в %d:%d:%d\n"), systemTime.wDay, systemTime.wMonth, systemTime.wYear, systemTime.wHour + 3, systemTime.wMinute, systemTime.wSecond );*/ } } void printCreateDirectory() { _tprintf(_T("Введите адрес создаваемого каталога: ")); wchar_t filename[1024]; fgetws(filename, sizeof(filename), stdin); filename[wcslen(filename) - 1] = 0; BOOL bStatus = CreateDirectoryW(filename, NULL); if (bStatus) return; DWORD error = GetLastError(); if (error == ERROR_ALREADY_EXISTS) _tprintf(_T("Каталог уже существует\n")); else if (error == ERROR_PATH_NOT_FOUND) _tprintf(_T("Неправильный путь\n")); } void printReadFile() { _tprintf(_T("Введите адрес файла: ")); wchar_t filename[1024]; fgetws(filename, sizeof(filename), stdin); filename[wcslen(filename) - 1] = 0; char buffer[MAX_PATH]; DWORD bytesRead; int numBytes; ZeroMemory(buffer, MAX_PATH); HANDLE hFile = CreateFile( filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { _tprintf(_T("Не найден файл \n")); } else { _tprintf(_T("Введите колличество байт для чтения: ")); wscanf(L"%d", &numBytes); ReadFile(hFile, buffer, numBytes, &bytesRead, NULL); buffer[bytesRead] = '\0'; _tprintf(_T("Чтение %d байт из файла:\n"), bytesRead); _tprintf(_T("%s\n"), buffer); } }