add help cd;fix bug:cd into a relative path

This commit is contained in:
2024-07-14 20:23:13 +08:00
parent 5953d603ae
commit 29b48a8e98
3 changed files with 11 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
cd - changes the working directory<br/>
if the directory doesn't exist or the directory is a file, it will throw an error<br/>
if no directory is specified, it will change the working directory to the previous directory<br/>
if the directory is a relative path, it will change the working directory to the relative path from the current directory<br/>
if the directory is an absolute path, it will change the working directory to the absolute path<br/>
+1
View File
@@ -1,5 +1,6 @@
clear - clears the screen<br/>
pwd - shows the working directory<br/>
mkdir - creates a new directory<br/>
cd - changes the working directory<br/>
help - displays this help message<br/>
type help [command] to show more details<br/>
+5 -3
View File
@@ -8,7 +8,7 @@ if (file_get_contents("pwd.txt") == NULL) {
file_put_contents("pwd.txt", "/");
}
$pwd = file_get_contents("pwd.txt");
if(!opendir("fileroot" . $pwd)){
if (!opendir("fileroot" . $pwd)) {
!file_put_contents("pwd.txt", "/");
}
if (!opendir("fileroot")) {
@@ -52,10 +52,12 @@ if (!opendir("fileroot")) {
}
} else if ($commands[0] == "clear" & sizeof($commands) == 1) {
file_put_contents("recent.txt", "");
} else if ($commands[0] == "cd" & sizeof($commands) == 2) {
if ($commands[1] == "..") {
} else if ($commands[0] == "cd") {
if ($commands[1] == ".." || sizeof($commands) == 1) {
$pwd = substr($pwd, 0, strrpos($pwd, "/"));
file_put_contents("pwd.txt", $pwd);
} else if (str_starts_with($commands[1], "/")) {
file_put_contents("pwd.txt", $commands[1]);
} else {
if (opendir("fileroot" . $pwd . "/" . $commands[1])) {
if ($pwd == "/")