Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <io.h> // не робит
- #include <dirent.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, EXIT = 4
- };
- int menu;
- do {
- system("clear");
- cout << "1. Rename file\n2. Remove file\n3. Show all files or directory\n4. Exit" << endl;
- cout << "Enter item from menu: ";
- cin >> menu;
- switch (menu) {
- case RENAME:
- renameFile();
- break;
- case REMOVE:
- removeFile();
- break;
- case DIRECTORY:
- Dir();
- case EXIT:
- exit(1);
- default:
- cout << "Error! " << endl;
- break;
- }
- } while (true);
- }
- 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";
- system("pause");
- }
- 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(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 in " << path;
- system("pause");
- _findclose(done);
- delete fileinfo;
- }
- void renameDirectory() {
- 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";
- cin.ignore();
- }
- void removeDirectory() {
- char name[255];
- cout << "Enter name of directory: ";
- cin >> name;
- if (remove(name) != 0) {
- cout << "Couldn't remove directory! \n";
- return;
- }
- cout << "Ok... " << endl;
- cin.ignore();
- }
- void createDirectory() {
- char name[255];
- cout << "Enter name: ";
- cin >> name;
- if (_mkdir(name, 0) == -1) {
- cout << "Couldn't remove directory! \n";
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement