forked from ahmeddrawy/Command-Line-Interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvCommand.java
More file actions
56 lines (50 loc) · 1.61 KB
/
mvCommand.java
File metadata and controls
56 lines (50 loc) · 1.61 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
package com.company;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public class mvCommand extends Command {
mvCommand(@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);
}
mvCommand(@NotNull String [] _args , Path _path){
args = new String[_args.length];
for (int i = 0 ; i <args.length ; ++i )
args[i] = _args[i];
// mPath = _path;
TerminalPath = _path;
myPath = _path;
}
protected boolean check() {
return DirectoryExist(myPath) && args.length==2;
}
protected void run(String path) {
if(check()) {
args[0] = toAbsolutePath(args[0]);
args[1] = toAbsolutePath(args[1]);
//File source = new File(args[0]);
String destination = args[1];
String source= args[0];
try {
File afile = new File(source);
if (afile.renameTo(new File(destination + '/' +afile.getName())) ){
System.out.println("File is moved successful!");
} else {
System.out.println("File is failed to move!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
else {
System.out.println("no such arguments");
}
}
protected void ShowArguments() {
///todo
}
}