-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.java
More file actions
92 lines (82 loc) · 2.08 KB
/
Copy pathMenu.java
File metadata and controls
92 lines (82 loc) · 2.08 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.File;
import java.util.ArrayList;
public class Menu{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private int selection;
public Menu(){
}
public void showMainOptions(){
System.out.println("\nOptions:"
+"\n 1. Go up"
+"\n 2. Go to folder"
+"\n 3. Read current"
+"\n 4. Clean current directory"
+"\n "
+"\n Default: exit "
+"");
}
public String askPath(){
String path = ".";
System.out.println("\nSet path?:"
+"\n 1. yes"
+"\n 2. no"
+"\n");
switch ( chooseOption() ){
case 1:
System.out.println("\nWrite path:\n");
path = readString();
break;
default:
break;
}
return path;
}
public File selectFolder(File[] files){
boolean isItDone;
isItDone = false;
int count = 0;
ArrayList<File> listFolders = new ArrayList<File>();
while( !isItDone ){
System.out.println("Choose: " + files.length );
count = 0;
for(int i=0;i<files.length;i++){
if(files[i].isDirectory()){
System.out.println( "[ " + count + " ] " + files[i].getName() );
listFolders.add( files[i] );
count++;
}
}
selection = chooseOption();
if( selection >= 0 && selection < files.length ){
isItDone = true;
}
}
return listFolders.get(selection);
}
public int chooseOption(){
int i = 0;
try{
i = Integer.parseInt(br.readLine());
} catch( IOException e ){
System.out.println( "Error: " + e.getMessage() );
} catch( NumberFormatException nfe ){
System.out.println( "Error: " + nfe.toString() );
}
return i;
}
public String readString(){
String path = ".";
try{
path = br.readLine();
} catch( IOException e ){
System.out.println( "Error: " + e.getMessage() );
}
return path;
}
public void sayGoodBye(){
System.out.println( "Good bye (:");
}
}