Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

Напиши програму на С++ которая получит папку от пользователя и найдет там последний…

  1. User

    Напиши програму на С++ которая получит папку от пользователя и найдет там последний созданный файл, без исользование классов и других библиотек: #include <stdio.h> #include #include <io.h> using namespace std;

  2. Assistant

    #include <stdio.h> #include #include <io.h> #include #include <Windows.h>

    int main() { std::string folderPath; std::cout << "Enter folder path: "; std::getline(std::cin, folderPath);

    WIN32_FIND_DATAA findData;
    HANDLE hFind = FindFirstFileA((folderPath + "/*").c_str(), &findData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        std::cout << "Failed to find files in the specified folder." << std::endl;
        return -1;
    }
    
    FILETIME lastCreatedTime = findData.ftCreationTime;
    std::string lastCreatedFileName = findData.cFileName;
    
    while (FindNextFileA(hFind, &findData))
    {
        if (findData.ftCreationTime.dwHighDateTime > lastCreatedTime.dwHighDateTime ||
            (findData.ftCreationTime.dwHighDateTime == lastCreatedTime.dwHighDateTime &&
                findData.ftCreationTime.dwLowDateTime > lastCreatedTime.dwLowDateTime))
        {
            lastCreatedTime = findData.ftCreationTime;
            lastCreatedFileName = findData.cFileName;
        }
    }
    
    FindClose(hFind);
    
    std::cout << "Last created file: " << lastCreatedFileName << std::endl;
    
    return 0;
    

    }