-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCdCommand.java
More file actions
35 lines (33 loc) · 1.2 KB
/
CdCommand.java
File metadata and controls
35 lines (33 loc) · 1.2 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
package IO;
import java.io.File;
public class CdCommand extends Command{
public CdCommand(){
super("cd");
}
@Override
public void action(String[] cmd) {
if (cmd.length > 1) {
// Kezelje a "cd .." parancsot a szülő könyvtárba lépéshez
if ("..".equals(cmd[1])) {
File parentDir = Main.wd.getParentFile();
if (parentDir != null && parentDir.exists()) {
Main.wd = parentDir;
System.out.println("Moved to parent directory: " + Main.wd.getPath());
} else {
System.out.println("No parent directory.");
}
} else {
// Kezelje a normál könyvtár váltást
File newDir = new File(Main.wd, cmd[1]);
if (newDir.exists() && newDir.isDirectory()) {
Main.wd = newDir;
System.out.println("Changed directory to: " + Main.wd.getPath());
} else {
System.out.println("Directory does not exist.");
}
}
} else {
System.out.println("No directory specified.");
}
}
}