Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <io.h>
- #include <direct.h>
- #include <cstring>
- using namespace std;
- void renameFile();
- void removeFile();
- void Dir();
- void renameDirectory();
- void removeDirectory();
- void createDirectory();
- int main() {
- enum m{RENAME = 1, REMOVE = 2, DIRECTORY = 3};
- int menu;
- do
- {
- system("cls");
- cout << "1. Rename file\n2. Remove file\n3. Show all files or direcotory\n4. Exit" << endl;
- cout << "Enter item from menu: ";
- cin >> menu;
- switch (menu)
- {case 1:
- renameFile();
- break;
- case 2:
- removeFile();
- break;
- case 3:
- Dir();
- case 4:
- exit(1);
- break;
- default:
- cout << "Error! " << endl;
- break;
- }
- } while (true);
- return 0;
- }
- void renameFile()
- {
- char oldName[255], newName[255];
- cout << "Enter old name: ";
- cin >> oldName;
- cout << "Enter new name: ";
- cin >> newName;
- if (rename(oldName, newName) != 0)
- {
- cout << "Couldn't rename file " << endl;
- return;
- }
- cout << "Ok! \n";
- }
- void removeFile()
- {
- char name[255];
- cout << "Enter name of file: ";
- cin >> name;
- if (remove(name) != 0)
- {
- cout << "Couldn't remove file! \n";
- return;
- }
- cout << "Ok... " << endl;
- system("pause");
- }
- void Dir()
- {
- char path[255];
- cout << "Enter path: ";
- cin >> path;
- char mask[25];
- cout << "Enter mask like *.* or *.txt etc...: ";
- cin >> mask;
- strcat_s(path, mask);
- _finddata_t* fileinfo = new _finddata_t;
- long done = _findfirst(path, fileinfo);
- int count{};
- int isFile = done;
- while (isFile != -1)
- {
- count++;
- cout << fileinfo->name << "\n\n";
- isFile = _findnext(done, fileinfo);
- }
- cout << " Was found " << count << " " << "file's " << path;
- system("pause");
- _findclose(done);
- delete fileinfo;
- }
- void renameDirectory()
- {
- }
- void removeDirectory()
- {
- }
- void createDirectory()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement