-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
219 lines (195 loc) · 4.84 KB
/
Program.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using System;
using System.IO;
using System.Runtime.CompilerServices;
/*
* TreeBuilder: A console app that will allow users to design
* customized directory trees to be applied to a current "root"
* path. Largely based from code in a Java version from 2018.
*
* Authored by Valenthyne, June 4 2020 - undetermined
*/
namespace TreeBuilder
{
static class Path
{
public static String path;
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to TreeBuilder!");
bool stay = true;
// Set the default path to C drive
Path.path = "C:\\";
while (stay)
{
MainMenu();
char sel = Console.ReadKey().KeyChar;
Console.WriteLine("\n");
switch (sel)
{
case '1': NavMenu();
break;
case '2': BranchMenu();
break;
case '3': GenMenu();
break;
default: stay = false;
break;
}
}
Console.WriteLine("Thank you for using TreeBuilder!");
Console.ReadKey();
}
// Method to print the menu for user input
static void MainMenu()
{
Console.WriteLine("\n Main Menu\n");
Console.WriteLine(" [1]: Navigation");
Console.WriteLine(" [2]: Branching");
Console.WriteLine(" [3]: Generation");
Console.WriteLine(" [4]: Exit");
Console.Write("\nSelect : ");
}
static void NavMenu()
{
bool stay = true;
while (stay)
{
Console.WriteLine("\n Navigation Menu\n");
Console.WriteLine("Current Path: " + Path.path + "\n");
Console.WriteLine(" [1]: Change Directory");
Console.WriteLine(" [2]: Previous Directory");
Console.WriteLine(" [3]: Drive Selection");
Console.WriteLine(" [4]: Print Contents");
Console.WriteLine(" [5]: Return");
Console.Write("\nSelect : ");
char sel = Console.ReadKey().KeyChar;
Console.WriteLine("\n");
switch (sel)
{
case '1': // Changing the directory from current path
Console.Write("Enter destination: ");
String dest = Console.ReadLine();
String dir = Path.path + dest;
if (Directory.Exists(dir))
{
Path.path = dir + "\\";
Console.WriteLine("New path: " + Path.path);
}
else
{
Console.WriteLine("Directory '" + dir + "' does not exist.");
}
break;
case '2': // Moving "back" a directory from current path
String modifiedPath = GoBack(Path.path);
if (Directory.Exists(modifiedPath))
{
Path.path = modifiedPath;
Console.WriteLine("New path: " + Path.path);
}
else
{
Console.WriteLine("Directory does not exist.");
}
break;
case '3': // Change to the root directory of a certain drive
Console.Write("Enter preferred drive (letter only): ");
String drive = Console.ReadLine() + ":\\";
if (Directory.Exists(drive))
Path.path = drive;
else
Console.WriteLine("Drive does not exist or is unavailable.");
break;
case '4': // Print all directories present within the current path
String[] directories = Directory.GetDirectories(Path.path);
if (directories.Length != 0)
{
foreach (String s in directories)
{
Console.WriteLine(s);
}
} else
{
Console.WriteLine("No sub-directories present.");
}
break;
default:
stay = false;
break;
}
}
}
// "Safe" algorithm credited to Ivan Stoev (https://stackoverflow.com/a/34414057)
static String GoBack(String path)
{
String root = "C:\\";
int lIndex = path.LastIndexOf("\\");
int stlIdex = lIndex > 0 ? path.LastIndexOf("\\", lIndex - 1) : -1;
if (stlIdex >= 0)
{
return path.Substring(0, stlIdex);
}
else
{
return root;
}
}
static void BranchMenu()
{
bool stay = true;
while (stay)
{
Console.WriteLine("\n Branch Menu\n");
Console.WriteLine(" [1]: Design Branch");
Console.WriteLine(" [2]: View Branch");
Console.WriteLine(" [3]: Clear Branch");
Console.WriteLine(" [4]: Return");
Console.Write("\nSelect : ");
char sel = Console.ReadKey().KeyChar;
Console.WriteLine("\n");
switch (sel)
{
case '1':
break;
case '2':
break;
case '3':
break;
default:
stay = false;
break;
}
}
}
static void GenMenu()
{
bool stay = true;
while (stay)
{
Console.WriteLine("\n Generate Menu\n");
Console.WriteLine(" [1]: Create Directories");
Console.WriteLine(" [2]: Generate Branch");
Console.WriteLine(" [3]: Unload Branch");
Console.WriteLine(" [4]: Return");
Console.Write("\nSelect : ");
char sel = Console.ReadKey().KeyChar;
Console.WriteLine("\n");
switch (sel)
{
case '1':
break;
case '2':
break;
case '3':
break;
default:
stay = false;
break;
}
}
}
}
}