Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #define LARGE_FILE_SIZE (10 * 1024 * 1024) // 10 MB
- // Globalne varijable za praćenje rezultata
- int largeFileCount = 0;
- FILETIME oldestFileTime;
- int oldestFileSet = 0;
- wchar_t oldestFileName[MAX_PATH];
- // Funkcija za usporedbu datuma
- int compareFileTime(FILETIME ft1, FILETIME ft2) {
- return (ft1.dwHighDateTime < ft2.dwHighDateTime) ||
- (ft1.dwHighDateTime == ft2.dwHighDateTime && ft1.dwLowDateTime < ft2.dwLowDateTime);
- }
- // Funkcija za obradu datoteke
- void processFile(const wchar_t* filePath, const WIN32_FIND_DATA* fileData) {
- LARGE_INTEGER fileSize;
- fileSize.LowPart = fileData->nFileSizeLow;
- fileSize.HighPart = fileData->nFileSizeHigh;
- // Provjera je li datoteka "velika"
- if (fileSize.QuadPart >= LARGE_FILE_SIZE) {
- largeFileCount++;
- }
- // Ažuriraj najstariji datum
- if (!oldestFileSet || compareFileTime(fileData->ftCreationTime, oldestFileTime)) {
- oldestFileTime = fileData->ftCreationTime;
- wcscpy_s(oldestFileName, filePath);
- oldestFileSet = 1;
- }
- }
- // Funkcija za postorder obilazak direktorija
- void traverseDirectoryPostorder(const wchar_t* directoryPath) {
- WIN32_FIND_DATA findFileData;
- HANDLE hFind;
- wchar_t searchPath[MAX_PATH];
- // Kreiranje putanje za pretragu ("<direktorij>\*")
- swprintf(searchPath, MAX_PATH, L"%s\\*", directoryPath);
- hFind = FindFirstFile(searchPath, &findFileData);
- if (hFind == INVALID_HANDLE_VALUE) {
- return; // Ako direktorij nije dostupan, izađi
- }
- do {
- // Preskoči "." i ".."
- if (wcscmp(findFileData.cFileName, L".") == 0 || wcscmp(findFileData.cFileName, L"..") == 0) {
- continue;
- }
- wchar_t fullPath[MAX_PATH];
- swprintf(fullPath, MAX_PATH, L"%s\\%s", directoryPath, findFileData.cFileName);
- if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- // Prvo obradi poddirektorije (postorder pristup)
- traverseDirectoryPostorder(fullPath);
- }
- else {
- // Obradi datoteku
- processFile(fullPath, &findFileData);
- }
- } while (FindNextFile(hFind, &findFileData) != 0);
- // Nakon obrade svih poddirektorija, obradi trenutni direktorij (postorder pristup)
- FindClose(hFind);
- }
- // Glavni program
- int wmain(int argc, wchar_t* argv[]) {
- if (argc != 2) {
- wprintf(L"Upotreba: %s <početni direktorij>\n", argv[0]);
- return 1;
- }
- // Pokreni postorder obilazak direktorija
- traverseDirectoryPostorder(argv[1]);
- // Ispis rezultata
- wprintf(L"Broj velikih datoteka (>= 10 MB): %d\n", largeFileCount);
- if (oldestFileSet) {
- SYSTEMTIME st;
- FileTimeToSystemTime(&oldestFileTime, &st);
- wprintf(L"Najstarija datoteka: %s\n", oldestFileName);
- wprintf(L"Datum najstarije datoteke: %02d.%02d.%04d.\n",
- st.wDay, st.wMonth, st.wYear);
- }
- else {
- wprintf(L"Nije pronađena niti jedna datoteka.\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement