PHP
php
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
<?php
// This script outputs a tree of files and directories using recursion. It works in both command line (terminal) and server
$preOpenTag = '';
$preCloseTag = '';
if (php_sapi_name() != 'cli') {
$preOpenTag = '<pre>';
$preCloseTag = '</pre>';
}
function showTree($folder, $indent)
{
$files = scandir($folder);
foreach ($files as $file) {
if (($file == '.') || ($file == '..')) {
continue;
}
$path = $folder . '/' . $file;
if (is_link($path) || !is_dir($path) || (is_dir($path) && !is_readable($path))) {
echo $indent . $file . "\n";
} else {
echo $indent . $file . "\n";
showTree($path, $indent . "\t");
}
}
}
echo $preOpenTag;
showTree("./", "");
echo $preCloseTag;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run