-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrmdirCommand.java
More file actions
52 lines (47 loc) · 1.5 KB
/
rmdirCommand.java
File metadata and controls
52 lines (47 loc) · 1.5 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
package com.company;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public class rmdirCommand extends Command {
rmdirCommand(@NotNull String [] _args , String _path) {
args = new String[_args.length];
for (int i = 0 ; i <args.length ; ++i )
args[i] = _args[i];
TerminalPath = Paths.get(_path);
myPath = Paths.get(_path);
}
rmdirCommand(@NotNull String [] _args , Path _path){
args = new String[_args.length];
for (int i = 0 ; i <args.length ; ++i )
args[i] = _args[i];
TerminalPath = _path;
myPath = _path;
}
protected boolean check() {
return DirectoryExist(myPath) && args.length==1;
}
protected void run(String path) {
args[0] = toAbsolutePath(args[0]);
File dir = new File(args[0]);
TerminalPath = Paths.get(path);
if (dir.isDirectory() == false) {
System.out.println("Not a directory.");
return;
} else if (check() == false) {
System.out.println("too much arguments");
return;
} else {
dir.delete();
}
/*
File dir = new File(args[0]);
File[] files = dir.listFiles();
for (File file : files) {
file.delete();
}*/ // deletes directories recursively (if a directory has another directories inside it)
}
protected void ShowArguments() {
///todo
}
}