summaryrefslogtreecommitdiff
path: root/shell/bin/ls.php
diff options
context:
space:
mode:
Diffstat (limited to 'shell/bin/ls.php')
-rw-r--r--shell/bin/ls.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/shell/bin/ls.php b/shell/bin/ls.php
new file mode 100644
index 0000000..fa01f2e
--- /dev/null
+++ b/shell/bin/ls.php
@@ -0,0 +1,34 @@
+<?php
+function main($args) {
+ if (count($args)<2) {
+ $args[]='.';
+ }
+ $ret=0;
+ $me = array_shift($args);
+ foreach ($args as $name) {
+ if (file_exists($name)) {
+ if (is_dir($name)) {
+ @$dh = opendir($name);
+ if ($dh === false) {
+ echo $me.': can not open directory: `'.$name."'\n";
+ $ret++;
+ } else {
+ if (count($args)>1) { echo $name.":\n"; }
+ $files = array();
+ while (false !== ($file = readdir($dh))) {
+ $files[]="$file";
+ }
+ sort($files);
+ echo implode("\n",$files)."\n";
+ closedir($dh);
+ }
+ } else {
+ echo $name."\n";
+ }
+ } else {
+ echo $me.': file does not exist: `'.$name."'\n";
+ $ret++;
+ }
+ }
+ return $ret;
+}