From f2c917aacedb4ebfe77bc75d5d4d4e3d330aa92a Mon Sep 17 00:00:00 2001 From: NIHAL T P Date: Sun, 12 Oct 2025 17:09:11 +0530 Subject: [PATCH 1/4] Add TreeCommand to display directory structure Closes #13 --- src/main/java/com/mycmd/App.java | 1 + .../java/com/mycmd/commands/TreeCommand.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/com/mycmd/commands/TreeCommand.java 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..0e2182a --- /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); + } + } + } +} From 23a40a2709e63448b91176783206716d51f1d058 Mon Sep 17 00:00:00 2001 From: NIHAL T P Date: Sun, 12 Oct 2025 17:25:30 +0530 Subject: [PATCH 2/4] Update checklist to mark additional commands --- CheckList.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 From 0fd89197b9368d6fba17f6740cec7662ee740f0c Mon Sep 17 00:00:00 2001 From: NIHAL T P Date: Sun, 12 Oct 2025 20:34:17 +0530 Subject: [PATCH 3/4] Update src/main/java/com/mycmd/commands/TreeCommand.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main/java/com/mycmd/commands/TreeCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mycmd/commands/TreeCommand.java b/src/main/java/com/mycmd/commands/TreeCommand.java index 0e2182a..bde19f7 100644 --- a/src/main/java/com/mycmd/commands/TreeCommand.java +++ b/src/main/java/com/mycmd/commands/TreeCommand.java @@ -4,7 +4,7 @@ import com.mycmd.ShellContext; import java.io.File; -public class TreeCommand implements Command{ +public class TreeCommand implements Command { public void execute(String[] args, ShellContext context){ File[] files = context.getCurrentDir().listFiles(); From 09af437a15962bdedaa8d563ca3aa6e5579417cc Mon Sep 17 00:00:00 2001 From: NIHAL T P Date: Sun, 12 Oct 2025 20:34:26 +0530 Subject: [PATCH 4/4] Update src/main/java/com/mycmd/commands/TreeCommand.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main/java/com/mycmd/commands/TreeCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mycmd/commands/TreeCommand.java b/src/main/java/com/mycmd/commands/TreeCommand.java index bde19f7..3fb045e 100644 --- a/src/main/java/com/mycmd/commands/TreeCommand.java +++ b/src/main/java/com/mycmd/commands/TreeCommand.java @@ -5,7 +5,7 @@ import java.io.File; public class TreeCommand implements Command { - public void execute(String[] args, ShellContext context){ + public void execute(String[] args, ShellContext context) { File[] files = context.getCurrentDir().listFiles(); if (files == null || files.length == 0) {