diff --git a/main.c b/main.c index 70f059a..e4205d7 100644 --- a/main.c +++ b/main.c @@ -45,8 +45,8 @@ int getVolumeInformation() { long getFileSize(LPCSTR path) { printf("- GetFileSize:\n"); HANDLE hFile; - DWORD fileSize; - unsigned long structLargeInt; + unsigned long long high; + unsigned long long low; // �������� ����� hFile = CreateFile(path, GENERIC_READ, @@ -55,15 +55,20 @@ long getFileSize(LPCSTR path) { OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + printf("�� ������� ������� ����\n"); + CloseHandle(hFile); + return 1; + } // ��������� ������� ����� - structLargeInt = GetFileSize(hFile, NULL); + low = GetFileSize(hFile, (LPDWORD) &high); // �������� ����� CloseHandle(hFile); // ����� ������� ����� - printf("������ �����: %lu ����\n", structLargeInt); + printf("������ �����: %llu\n", high << 32 | low); return 0; } int findNextFile() { @@ -114,6 +119,11 @@ int compareFileTime(LPCSTR path_1, LPCSTR path_2) { OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (file1 == INVALID_HANDLE_VALUE) { + printf("�� ������� ������� ���� 1\n"); + CloseHandle(file1); + return 1; + } // ����� ��������� ������� ����� GetFileTime(file1, NULL, NULL, &fileTime1); @@ -129,6 +139,11 @@ int compareFileTime(LPCSTR path_1, LPCSTR path_2) { OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (file2 == INVALID_HANDLE_VALUE) { + printf("�� ������� ������� ���� 2\n"); + CloseHandle(file2); + return 1; + } // �������� ����� ��������� ������� ����� GetFileTime(file2, NULL, NULL, &fileTime2); @@ -178,31 +193,36 @@ int setLocalTime() { return 0; } -void getFileAttributes(LPCSTR path){ +int getFileAttributes(LPCSTR path){ DWORD fileAttributes = GetFileAttributes(path); + if (fileAttributes == INVALID_FILE_ATTRIBUTES) + { + printf("������ �������� �����.\n"); + return 1; + } if (fileAttributes & FILE_ATTRIBUTE_READONLY) { printf("\n/Read-only"); } if (fileAttributes & FILE_ATTRIBUTE_HIDDEN) { printf("\n/Hidden"); } - if (fileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + if (fileAttributes & FILE_ATTRIBUTE_ARCHIVE) { printf("\n/Directory"); }// � ��� ����� ��� ������ ��������� �����... printf("\n"); } -int setFileAttributes(LPCSTR path) { +int setFileAttributes(LPCSTR path, DWORD dwFileAttributes) { printf("- SetFileAttributes:\n"); // G��� � ����� // ���������� �������� ����� - SetFileAttributes(path, (DWORD) NULL); + SetFileAttributes(path, (DWORD) 0); // ������� �������� ����� printf("\t������� �������� ����� �� ������: "); getFileAttributes(path); // ������������� �������� ����� - DWORD newFileAttributes = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY; + DWORD newFileAttributes = dwFileAttributes; BOOL result = SetFileAttributes( path, (DWORD) newFileAttributes); printf("\t������� �������� ����� ����� ������: "); @@ -253,20 +273,28 @@ int createFile() { int main() { setlocale(LC_ALL, "Rus"); - printf("\n----------------------------\n"); + printf("\n----------------------------\n----------------------------\n----------------------------\n"); printf("\t���������� � ������:\n"); - getLogicalDriveStrings();// + ��������� ���� ������ - getVolumeInformation();// + ��������� ���������� � �������� ������� ���������� ����������� ����� + // getLogicalDriveStrings();// + ��������� ���� ������ + // getVolumeInformation();// + ��������� ���������� � �������� ������� ���������� ����������� ����� printf("\n------------------------------------------\n"); printf("\t���������� � ������ � �����������:\n"); getFileSize("text.txt");// + �������� ������ ����� - findNextFile();// + ����� ���������� ����� � ����� ������ - getWindowsDirectory();// + ���� � ��������� �������� ������� + getFileSize("tex������t.txt");// + �������� ������ ����� + // findNextFile();// + ����� ���������� ����� � ����� ������ + // getWindowsDirectory();// + ���� � ��������� �������� ������� compareFileTime("text.txt", "text2.txt.");// + ����������� ����� �� ������ ����� ����� printf("\n----------------------------\n"); printf("\t����������� �������:\n"); - setLocalTime();// + ���������� ������� ���� � ����� - setFileAttributes("text3.txt");// + ��������� �������� ��������� - createFile();// + �������/������� ���� - CopyFile("text.txt", "text3.txt", 0);// ����������� ���� + // setLocalTime();// + ���������� ������� ���� � ����� + printf("\t������� ������ ������� ��� ��������� �����: 1 - ������ ��� ������, 2 - �������, 3 - ��������\n"); + int chislo = 0; + scanf("%d", &chislo); + if (chislo == 1 || chislo == 2 || chislo == 3) + setFileAttributes("text3.txt", chislo);// + ��������� �������� ��������� + else { + printf("������ �������� ����� ��������\n"); + } + // createFile();// + �������/������� ���� + // CopyFile("text.txt", "text3.txt", 0);// ����������� ���� } diff --git a/main.exe b/main.exe index 0985ba4..8a47060 100644 Binary files a/main.exe and b/main.exe differ