Advertisement
Baxram97

Untitled

Mar 8th, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <direct.h>
  5. #include <cstring>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. void renameFile();
  11.  
  12. void removeFile();
  13.  
  14. void Dir();
  15.  
  16.  
  17. void renameDirectory();
  18.  
  19. void removeDirectory();
  20.  
  21. void createDirectory();
  22.  
  23.  
  24. int main() {
  25.  
  26.     enum m{RENAME = 1, REMOVE = 2, DIRECTORY = 3};
  27.     int menu;
  28.     do
  29.     {
  30.         system("cls");
  31.  
  32.         cout << "1. Rename file\n2. Remove file\n3. Show all files or direcotory\n4. Exit" << endl;
  33.         cout << "Enter item from menu: ";
  34.         cin >> menu;
  35.         switch (menu)
  36.         {case 1:
  37.             renameFile();
  38.             break;
  39.         case 2:
  40.             removeFile();
  41.             break;
  42.         case 3:
  43.             Dir();
  44.         case 4:
  45.             exit(1);
  46.             break;
  47.         default:
  48.             cout << "Error! " << endl;
  49.             break;
  50.         }
  51.     } while (true);
  52.  
  53.     return 0;
  54. }
  55.  
  56. void renameFile()
  57. {
  58.     char oldName[255], newName[255];
  59.     cout << "Enter old name: ";
  60.     cin >> oldName;
  61.  
  62.     cout << "Enter new name: ";
  63.     cin >> newName;
  64.     if (rename(oldName, newName) != 0)
  65.     {
  66.         cout << "Couldn't rename file " << endl;
  67.         return;
  68.     }
  69.     cout << "Ok! \n";
  70. }
  71.  
  72. void removeFile()
  73. {
  74.     char name[255];
  75.     cout << "Enter name of file: ";
  76.     cin >> name;
  77.     if (remove(name) != 0)
  78.     {
  79.         cout << "Couldn't remove file! \n";
  80.         return;
  81.     }
  82.     cout << "Ok... " << endl;
  83.     system("pause");
  84. }
  85.  
  86. void Dir()
  87. {
  88.     char path[255];
  89.     cout << "Enter path: ";
  90.     cin >> path;
  91.  
  92.     char mask[25];
  93.     cout << "Enter mask like *.* or *.txt etc...: ";
  94.     cin >> mask;
  95.  
  96.     strcat_s(path, mask);
  97.  
  98.     _finddata_t* fileinfo = new _finddata_t;
  99.  
  100.     long done = _findfirst(path, fileinfo);
  101.     int count{};
  102.     int isFile = done;
  103.     while (isFile != -1)
  104.     {
  105.         count++;
  106.         cout << fileinfo->name <<  "\n\n";
  107.         isFile = _findnext(done, fileinfo);
  108.     }
  109.     cout << " Was found " << count << " " << "file's " << path;
  110.     system("pause");
  111.     _findclose(done);
  112.     delete fileinfo;
  113. }
  114.  
  115.  
  116.  
  117. void renameDirectory()
  118. {
  119.  
  120. }
  121.  
  122. void removeDirectory()
  123. {
  124.  
  125. }
  126.  
  127. void createDirectory()
  128. {
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement