summaryrefslogtreecommitdiff
path: root/shell/bin/ls.php
blob: fa01f2ecb46e266989082757aa24d456055cf612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}