-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_5.cpp
More file actions
68 lines (59 loc) · 1.97 KB
/
8_5.cpp
File metadata and controls
68 lines (59 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
void displayDirectory(const map<string, vector<string>>& directory) {
if (directory.empty()) {
cout << "\nDirectory is empty.\n";
return;
}
cout << "\n=== Directory Structure ===\n";
for (const auto& pair : directory) {
const string& folder = pair.first;
const vector<string>& files = pair.second;
cout << "Folder: " << folder << "\nFiles:\n";
if (files.empty()) {
cout << " (No files in this folder)\n";
} else {
for (const auto& file : files) {
cout << " - " << file << "\n";
}
}
cout << endl;
}
}
int main() {
map<string, vector<string>> directory;
int choice;
string folder, file;
do {
cout << "\n1. Add Folder\n2. Add File to Folder\n3. Display Directory\n0. Exit\nChoice: ";
cin >> choice;
cin.ignore(); // To ignore leftover newline after number input
switch (choice) {
case 1:
cout << "Enter folder name: ";
getline(cin, folder); // Allows spaces in folder name
directory[folder]; // Creates empty folder if not exists
break;
case 2:
cout << "Enter folder name: ";
getline(cin, folder);
cout << "Enter file name: ";
getline(cin, file);
directory[folder].push_back(file); // Adds file to folder
break;
case 3:
displayDirectory(directory);
break;
case 0:
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
} while (choice != 0);
cout<<endl<<"24CE052_Pushtikansara"<<endl;
return 0;
}