-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLsCommand.java
More file actions
30 lines (26 loc) · 901 Bytes
/
LsCommand.java
File metadata and controls
30 lines (26 loc) · 901 Bytes
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
package IO;
import java.io.File;
public class LsCommand extends Command{
public LsCommand(){
super("ls");
}
@Override
public void action(String[] cmd) {
boolean detailed = cmd.length > 1 && "-l".equals(cmd[1]);
File[] files = Main.wd.listFiles();
if (files == null) {
System.out.println("No files found.");
return;
}
for (File file : files) {
if (detailed) {
// Méret megjelenítése byte-ban, és fájl típusának jelzése (d: könyvtár, f: fájl)
String type = file.isDirectory() ? "d" : "f";
System.out.println(String.format("%s - %s - %d bytes", file.getName(), type, file.length()));
} else {
// Alapvető lista, csak a nevekkel
System.out.println(file.getName());
}
}
}
}