From 0db1c556d4fc291fa8dd568c201b81e49f340585 Mon Sep 17 00:00:00 2001 From: Ivan2567 <78481838+Ivan2567@users.noreply.github.com> Date: Thu, 23 Nov 2023 01:32:06 +0300 Subject: [PATCH] lab1 --- Project1/Project1.sln | 31 +++ Project1/Project1/Old.txt | 1 + Project1/Project1/Project1.vcxproj | 136 +++++++++++++ Project1/Project1/Project1.vcxproj.filters | 22 ++ Project1/Project1/hello.c | 221 +++++++++++++++++++++ Project1/Project1/text.txt | 0 Project1/Project1/text2.txt | 0 7 files changed, 411 insertions(+) create mode 100644 Project1/Project1.sln create mode 100644 Project1/Project1/Old.txt create mode 100644 Project1/Project1/Project1.vcxproj create mode 100644 Project1/Project1/Project1.vcxproj.filters create mode 100644 Project1/Project1/hello.c create mode 100644 Project1/Project1/text.txt create mode 100644 Project1/Project1/text2.txt diff --git a/Project1/Project1.sln b/Project1/Project1.sln new file mode 100644 index 0000000..fc52006 --- /dev/null +++ b/Project1/Project1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32602.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcxproj", "{73FD34D1-9A70-4EC7-BB6C-61B4E6503125}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x64.ActiveCfg = Debug|x64 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x64.Build.0 = Debug|x64 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x86.ActiveCfg = Debug|Win32 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Debug|x86.Build.0 = Debug|Win32 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x64.ActiveCfg = Release|x64 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x64.Build.0 = Release|x64 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x86.ActiveCfg = Release|Win32 + {73FD34D1-9A70-4EC7-BB6C-61B4E6503125}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {02C511CF-3283-4A24-ABEE-DB5811E8294C} + EndGlobalSection +EndGlobal diff --git a/Project1/Project1/Old.txt b/Project1/Project1/Old.txt new file mode 100644 index 0000000..489ce0f --- /dev/null +++ b/Project1/Project1/Old.txt @@ -0,0 +1 @@ +old \ No newline at end of file diff --git a/Project1/Project1/Project1.vcxproj b/Project1/Project1/Project1.vcxproj new file mode 100644 index 0000000..0649d6e --- /dev/null +++ b/Project1/Project1/Project1.vcxproj @@ -0,0 +1,136 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {73fd34d1-9a70-4ec7-bb6c-61b4e6503125} + Project1 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + CompileAsC + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Project1/Project1/Project1.vcxproj.filters b/Project1/Project1/Project1.vcxproj.filters new file mode 100644 index 0000000..79d4255 --- /dev/null +++ b/Project1/Project1/Project1.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Файлы ресурсов + + + \ No newline at end of file diff --git a/Project1/Project1/hello.c b/Project1/Project1/hello.c new file mode 100644 index 0000000..9932d1a --- /dev/null +++ b/Project1/Project1/hello.c @@ -0,0 +1,221 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include +#include + +TCHAR szDrive[] = _T(" A:"); + +int main() +{ + setlocale(LC_ALL, "ru_RU.UTF8"); + SetConsoleOutputCP(65001); + SetConsoleCP(65001); + //getLogicalDrives(); + //getDiskFreeSpaceExA(); + //get_file_list(); + //getfiletime(); + //createDir(); + //removeDir(); + //compareFileTime(); + //setVolumeLabel(); + //moveFile(); + //deleteFile(); + + return 0; +} +int getLogicalDrives() { + DWORD uDriveMask = GetLogicalDrives(); +// printf("The bitmask of the logical drives in hex: %0X\n", uDriveMask); +// printf("The bitmask of the logical drives in decimal: %d\n", uDriveMask); + if (uDriveMask == 0) + printf("GetLogicalDrives() failed with failure code: %d\n", GetLastError()); + else + { + printf("This machine has the following logical drives:\n"); + while (uDriveMask) + { + // Use the bitwise AND, 1â€"available, 0-not available + if (uDriveMask & 1) + printf("%S ", (const char*)szDrive); + // increment, check next drive + ++szDrive[1]; + // shift the bitmask binary right + uDriveMask >>= 1; + } + printf("\n "); + } + return 0; +} + +int getDiskFreeSpaceExA() { + char n[10] = ""; + printf("Enter disc name\n"); + scanf(" %s", n); + LPCWSTR pszDrive = n; + BOOL test, fResult; + // 64 bits integer, low and high bytes + __int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes; + DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters; + // If the function succeeds, the return value is nonzero. If the function fails, the return value is 0 (zero). + test = GetDiskFreeSpaceExA( + pszDrive, + (PULARGE_INTEGER)&lpFreeBytesAvailable, + (PULARGE_INTEGER)&lpTotalNumberOfBytes, + (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes + ); + printf("\nUsing GetDiskFreeSpaceEx()...\n"); + // Check the return value + printf("The return value: %d, error code: %d\n", test, GetLastError()); + printf("Total number of free bytes available for user-caller: %ul\n", lpFreeBytesAvailable); + printf("Total number of bytes available for user: %ul\n", lpTotalNumberOfBytes); + printf("Total number of free bytes on disk: %ul\n", lpTotalNumberOfFreeBytes); + return 0; +} + + +int get_file_list() +{ + char n[8] = ""; + printf("Enter disc name\n"); + scanf("%s:", n); + HANDLE hFind, hFile; + WIN32_FIND_DATA data; + FILETIME ftCreate; + SYSTEMTIME systime, sysLocal; + + + hFind = FindFirstFileA(n, &data); + + if (hFind != INVALID_HANDLE_VALUE) { + do { + printf("%s\n ", data.cFileName); + //GetFileTime(&hFind, &ftCreate, NULL, NULL); + //FileTimeToSystemTime(&ftCreate, &systime); + //SystemTimeToTzSpecificLocalTime(NULL, &systime, &sysLocal); + //wprintf(L"CreationTime: %lu:%lu:%lu\n", sysLocal.wHour, sysLocal.wMinute, sysLocal.wSecond); + //printf("Created on: %02d/%02d/%d %02d:%02d\n", ssystimeystime.wDay, systime.wMonth, systime.wYear, systime.wHour, systime.wMinute); + } while (FindNextFileA(hFind, &data)); + FindClose(hFind); + } + return 0; +} +int getfiletime() +{ + HANDLE hFile1; + FILETIME ftCreate; + SYSTEMTIME stUTC, stLocal; + hFile1 = CreateFile(TEXT("text.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hFile1 == INVALID_HANDLE_VALUE) + { + printf("Could not open file, error %ul\n", GetLastError()); + return -1; + } + if (!GetFileTime(hFile1, &ftCreate, NULL, NULL)) + { + printf("Something wrong!\n"); + return FALSE; + } + FileTimeToSystemTime(&ftCreate, &stUTC); + printf("UTC System Time format:\n"); + printf("text.txt Created on: %02d/%02d/%d %02d:%02d\n",stUTC.wDay, stUTC.wMonth, stUTC.wYear, stUTC.wHour, stUTC.wMinute); + return 0; + +} + +int createDir() +{ + BOOL createD = CreateDirectory(L"NewFolder", NULL); + if (createD) + { + printf("Directory Created\n"); + } + return 0; +} +int removeDir() +{ + BOOL removeD = RemoveDirectory(L"NewFolder", NULL); + if (removeD) + { + printf("Directory Deleted\n"); + } + + return 0; +} +int compareFileTime() { + FILETIME fileTime1, fileTime2; + // первый файл + HANDLE file1 = CreateFile(TEXT("text.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + // время изменения первого файла + GetFileTime(file1, NULL, NULL, &fileTime1); + // закрываем первый файл + CloseHandle(file1); + // Открываем второй файл + HANDLE file2 = CreateFile(TEXT("text2.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + // Получаем время изменения второго файла + GetFileTime(file2, NULL, NULL, &fileTime2); + // Закрываем второй файл + CloseHandle(file2); + // Сравниваем время изменения файлов + int comparisonResult = CompareFileTime(&fileTime1, &fileTime2); + + if (comparisonResult == -1) { + wprintf(L"Файл 1 был изменен раньше файла 2\n"); + } + else if (comparisonResult == 1) { + wprintf(L"Файл 2 был изменен раньше файла 1\n"); + } + else { + wprintf(L"Время изменения файлов одинаково\n"); + } + return 0; +} +int setVolumeLabel(){ + LPSTR dirch = "S:\\"; + LPSTR dirn = "Storage"; + //LPSTR dirn = "Test"; + BOOL bbb = SetVolumeLabelA(dirch, dirn); + //if(bbb){wprintf("%b",bbb);} + return 0; +} + +int moveFile(){ + if (MoveFile(L"Old.txt",L"New.txt")){ + wprintf(L"Файл перемещён\n"); + } + else { + wprintf(L"Ошибка\n"); + } + return 0; +} +int deleteFile() { + if (DeleteFile(L"New.txt")) { + wprintf(L"Файл удалён\n"); + } + else { + wprintf(L"Ошибка\n"); + } + return 0; +} + +/* +GetLogicalDrivesFindFistFile + +GetDiskFreeSpaceExA+ + +FindFirstFile + +FindNextFile + + +GetFileTime+ + +CompareFileTime+ + +SetVolumeLabel+ + +CreatDirectory+ +RemoveDirectory+ + +MoveFile + +DeleteFile + +*/ \ No newline at end of file diff --git a/Project1/Project1/text.txt b/Project1/Project1/text.txt new file mode 100644 index 0000000..e69de29 diff --git a/Project1/Project1/text2.txt b/Project1/Project1/text2.txt new file mode 100644 index 0000000..e69de29