diff --git a/CheckList.md b/CheckList.md index a42781b..d6e8175 100644 --- a/CheckList.md +++ b/CheckList.md @@ -8,7 +8,7 @@ ## 🧭 System Information & Management - [ ] systeminfo -- [ ] hostname +- [x] hostname - [x] ver - [ ] vol - [ ] set @@ -38,7 +38,7 @@ - [x] move - [ ] rename / ren - [ ] attrib -- [ ] tree +- [x] tree - [x] type - [ ] more - [ ] find @@ -97,7 +97,7 @@ - [ ] net user - [ ] net localgroup - [ ] runas -- [ ] whoami +- [x] whoami - [ ] cacls - [ ] icacls - [ ] cipher @@ -111,9 +111,9 @@ - [ ] pause - [x] cls - [x] exit -- [ ] title -- [ ] color -- [ ] time +- [x] title +- [x] color +- [x] time - [x] date - [ ] shutdown - [ ] choice @@ -172,7 +172,7 @@ - [ ] call - [x] cd / chdir - [x] cls -- [ ] color +- [x] color - [x] copy - [x] date - [x] del / erase @@ -200,8 +200,8 @@ - [ ] setlocal - [ ] shift - [ ] start -- [ ] time -- [ ] title +- [x] time +- [x] title - [x] type - [x] ver - [ ] verify diff --git a/src/main/java/com/mycmd/App.java b/src/main/java/com/mycmd/App.java index e425f51..66d58c7 100644 --- a/src/main/java/com/mycmd/App.java +++ b/src/main/java/com/mycmd/App.java @@ -56,6 +56,7 @@ private static void registerCommands(Map commands) { commands.put("whoami", new WhoamiCommand()); commands.put("touch", new TouchCommand()); commands.put("time", new TimeCommand()); + commands.put("tree", new TreeCommand()); commands.put("date", new DateCommand()); } } diff --git a/src/main/java/com/mycmd/commands/TreeCommand.java b/src/main/java/com/mycmd/commands/TreeCommand.java new file mode 100644 index 0000000..3fb045e --- /dev/null +++ b/src/main/java/com/mycmd/commands/TreeCommand.java @@ -0,0 +1,37 @@ +package com.mycmd.commands; + +import com.mycmd.Command; +import com.mycmd.ShellContext; +import java.io.File; + +public class TreeCommand implements Command { + public void execute(String[] args, ShellContext context) { + File[] files = context.getCurrentDir().listFiles(); + + if (files == null || files.length == 0) { + System.out.println("No files found."); + return; + } + + System.out.println(context.getCurrentDir().getAbsolutePath()); + printDirectory(files, "", true); + System.out.println(); + } + + private void printDirectory(File[] files, String prefix, boolean isLast) { + if (files == null || files.length == 0) return; + + for (int i = 0; i < files.length; i++) { + File f = files[i]; + if (f.isHidden()) continue; + + boolean last = (i == files.length - 1); + System.out.println(prefix + (last ? "└───" : "├───") + f.getName()); + + if (f.isDirectory()) { + String newPrefix = prefix + (last ? " " : "│ "); + printDirectory(f.listFiles(), newPrefix, last); + } + } + } +}