Загрузка...

C++ Нужна помощь

Тема в разделе C/C++ создана пользователем zheni4ka 26 май 2022. 207 просмотров

  1. zheni4ka
    zheni4ka Автор темы 26 май 2022 0 9 сен 2021
    Нужно реализовать программу которая будет очищать пк. Задание звучит так:
    Разработка программы для удаления по расписанию
    ненужных файлов (*.bak, *.tmp,
    и.т.и.), определяемые пользователем и в
    указанных им каталогах.
    Готов заплатить

    Есть код но там куча ошибок а как реализовать не знаю....





    Код
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <sstream>
    #include <cstdint>
    #include <filesystem>
    using namespace std;
    using namespace fs = std::filesystem;


    void getFiles(const string& inpath, string outpath)
    {
    std::cout
    std::cin

    if (str = .old) {

    string mask = inpath + "\\*.old";
    WIN32_FIND_DATA FindFileData;
    HANDLE hfo;
    hfo = FindFirstFile(mask.c_str(), &FindFileData);

    ofstream output;
    output.open(outpath + "\\data.txt", ios_base::app);

    if (hfo != INVALID_HANDLE_VALUE)
    {
    do
    {
    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if (strcmp(FindFileData.cFileName, ".") == 0 ||
    strcmp(FindFileData.cFileName, "..") == 0) continue;
    getFiles(inpath + "\\" + FindFileData.cFileName, outpath);
    }
    else
    output << inpath << "\\" << FindFileData.cFileName << endl;

    } while (FindNextFile(hfo, &FindFileData) != 0);
    FindClose(hfo);
    }

    output.close();
    }


    else if (str = .old)
    {
    string mask = inpath + "\\*.syd";
    WIN32_FIND_DATA FindFileData;
    HANDLE hfs;
    hfs = FindFirstFile(mask.c_str(), &FindFileData);

    ofstream output;
    output.open(outpath + "\\data.txt", ios_base::app);

    if (hfs != INVALID_HANDLE_VALUE)
    {
    do
    {
    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if (strcmp(FindFileData.cFileName, ".") == 0 ||
    strcmp(FindFileData.cFileName, "..") == 0) continue;
    getFiles(inpath + "\\" + FindFileData.cFileName, outpath);
    }
    else
    output << inpath << "\\" << FindFileData.cFileName << endl;

    } while (FindNextFile(hfs, &FindFileData) != 0);
    FindClose(hfs);
    }

    output.close();
    }


    else if (str = .tmp) {
    string mask = inpath + "\\*.tmp";
    WIN32_FIND_DATA FindFileData;
    HANDLE hft;
    hft = FindFirstFile(mask.c_str(), &FindFileData);

    ofstream output;
    output.open(outpath + "\\data.txt", ios_base::app);

    if (hft != INVALID_HANDLE_VALUE)
    {
    do
    {
    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if (strcmp(FindFileData.cFileName, ".") == 0 ||
    strcmp(FindFileData.cFileName, "..") == 0) continue;
    getFiles(inpath + "\\" + FindFileData.cFileName, outpath);
    }
    else
    output << inpath << "\\" << FindFileData.cFileName << endl;

    } while (FindNextFile(hft, &FindFileData) != 0);
    FindClose(hft);
    }

    output.close();
    }


    else if (str = .bak) {
    string mask = inpath + "\\*.bak";
    WIN32_FIND_DATA FindFileData;
    HANDLE hfb;
    hfb = FindFirstFile(mask.c_str(), &FindFileData);

    ofstream output;
    output.open(outpath + "\\data.txt", ios_base::app);

    if (hf != INVALID_HANDLE_VALUE)
    {
    do
    {
    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if (strcmp(FindFileData.cFileName, ".") == 0 ||
    strcmp(FindFileData.cFileName, "..") == 0) continue;
    getFiles(inpath + "\\" + FindFileData.cFileName, outpath);
    }
    else
    output << inpath << "\\" << FindFileData.cFileName << endl;

    } while (FindNextFile(hfb, &FindFileData) != 0);
    FindClose(hfb);
    }

    output.close();
    }


    else if (str = .dos) {
    string mask = inpath + "\\*.dos";
    WIN32_FIND_DATA FindFileData;
    HANDLE hfd;
    hfd = FindFirstFile(mask.c_str(), &FindFileData);

    ofstream output;
    output.open(outpath + "\\data.txt", ios_base::app);

    if (hfd != INVALID_HANDLE_VALUE)
    {
    do
    {
    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if (strcmp(FindFileData.cFileName, ".") == 0 ||
    strcmp(FindFileData.cFileName, "..") == 0) continue;
    getFiles(inpath + "\\" + FindFileData.cFileName, outpath);
    }
    else
    output << inpath << "\\" << FindFileData.cFileName << endl;

    } while (FindNextFile(hfd, &FindFileData) != 0);
    FindClose(hfd);
    }

    output.close();
    }


    else if (str = .chk) {
    string mask = inpath + "\\*.chk";
    WIN32_FIND_DATA FindFileData;
    HANDLE hfc;
    hfc = FindFirstFile(mask.c_str(), &FindFileData);

    ofstream output;
    output.open(outpath + "\\data.txt", ios_base::app);

    if (hfc != INVALID_HANDLE_VALUE)
    {
    do
    {
    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if (strcmp(FindFileData.cFileName, ".") == 0 ||
    strcmp(FindFileData.cFileName, "..") == 0) continue;
    getFiles(inpath + "\\" + FindFileData.cFileName, outpath);
    }
    else
    output << inpath << "\\" << FindFileData.cFileName << endl;

    } while (FindNextFile(hfc, &FindFileData) != 0);
    FindClose(hfc);
    }

    output.close();
    }
    else {
    cout << "error"
    }

    int main()
    {
    cout << "Choose the type of file(.tmp/.bak/.old/.syd/.dos/.chk) and enter it";
    cin << str;
    AnsiString DirPath = Edit1->Text;
    TStringList* ToDel = new TStringList();
    ToDel->LoadFromFile("data.txt");
    AnsiString ObjectName;
    for (int i = ToDel->Count - 1; i >= 0; i--)
    {
    ObjectName = DirPath + ToDel->Strings[i];
    if (DirectoryExists)
    RemoveDir(ObjectName);
    (FileExists);
    DeleteFile(ObjectName);
    }
    delete ToDel;
    }
    }
     
Top
Загрузка...