add command ls

This commit is contained in:
2024-10-14 22:57:35 +08:00
parent 3da2914bfa
commit 0a3a07be1e
6 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -7,6 +7,6 @@ function help($commands)
} else if (sizeof($commands) == 2 && file_get_contents("static/help/$commands[1].txt") != NULL) {
file_put_contents("recent.txt", file_get_contents("static/help/$commands[1].txt"), FILE_APPEND);
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
file_put_contents("recent.txt", "Invalid number of arguments or command not found.<br/>", FILE_APPEND);
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
function ls($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 1) {
$files = scandir("fileroot" . $pwd);
foreach ($files as $file) {
file_put_contents("recent.txt", $file . "<br/>", FILE_APPEND);
}
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
+3
View File
@@ -0,0 +1,3 @@
make php
write help.txt <command_name>.txt
edit terminal.php
+2
View File
@@ -0,0 +1,2 @@
ls - lists the contents of a directory<br/>
usage: ls<br/>
+1
View File
@@ -2,6 +2,7 @@ cat - displays the contents of a file<br/>
cd - changes the working directory<br/>
clear - clears the screen<br/>
help - displays this help message<br/>
ls - lists the contents of a directory<br/>
mkdir - creates a new directory<br/>
pwd - shows the working directory<br/>
rm - deletes a file or directory<br/>
+3
View File
@@ -64,6 +64,9 @@ if (!opendir("fileroot")) {
} else if ($commands[0] == "cat") {
include "commands/cat.php";
cat($commands);
} else if ($commands[0] == "ls") {
include "commands/ls.php";
ls($commands);
} else {
file_put_contents("recent.txt", "Unknown command.<br/>try 'help' or 'help [command]'<br/>", FILE_APPEND);
}