Page 1 of 1
dos tree
Posted: Thu May 21, 2015 11:58 am
by Vegan
in the command prompt in Windows there is a tree command that can make a chart of folders
the problem is converting that to a web page
the goal was is to have a human friendly site map as opposed to ones that search engines use
Re: dos tree
Posted: Thu May 21, 2015 12:03 pm
by requinix
So why not just do the same thing using PHP code?
Re: dos tree
Posted: Thu May 21, 2015 12:14 pm
by Vegan
I am not sure how to do that with PHP, that would be ideal as I could then have the page generated on demand and no matter how much change, the map would be updated
Re: dos tree
Posted: Thu May 21, 2015 12:26 pm
by Celauran
Depends on how your site is structured. Is it front controlled or a bunch of page scripts?
Re: dos tree
Posted: Thu May 21, 2015 1:06 pm
by Vegan
its actually just a bunch of pages, stored in a bunch of folders
all I wanted was a tree of the actual folders, not the files
Re: dos tree
Posted: Thu May 21, 2015 2:59 pm
by Celauran
Re: dos tree
Posted: Thu May 21, 2015 3:11 pm
by Vegan
OK I found this function that looks like it had some potential
Now if you recall the DOS TREE command used crude line art, so I have seen stuff like that in UNICODE I was wondering if that would have any potential
Code: Select all
<?php
/**
* Get an array that represents directory tree
* @param string $directory Directory path
* @param bool $recursive Include sub directories
* @param bool $listDirs Include directories on listing
* @param bool $listFiles Include files on listing
* @param regex $exclude Exclude paths that matches this regex
*/
function directoryToArray($directory, $recursive = true, $listDirs = false, $listFiles = true, $exclude = '') {
$arrayItems = array();
$skipByExclude = false;
$handle = opendir($directory);
if ($handle) {
while (false !== ($file = readdir($handle))) {
preg_match("/(^(([\.]){1,2})$|(\.(svn|git|md))|(Thumbs\.db|\.DS_STORE))$/iu", $file, $skip);
if($exclude){
preg_match($exclude, $file, $skipByExclude);
}
if (!$skip && !$skipByExclude) {
if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) {
if($recursive) {
$arrayItems = array_merge($arrayItems, directoryToArray($directory. DIRECTORY_SEPARATOR . $file, $recursive, $listDirs, $listFiles, $exclude));
}
if($listDirs){
$file = $directory . DIRECTORY_SEPARATOR . $file;
$arrayItems[] = $file;
}
} else {
if($listFiles){
$file = $directory . DIRECTORY_SEPARATOR . $file;
$arrayItems[] = $file;
}
}
}
}
closedir($handle);
}
return $arrayItems;
}
?>
I am using a datacenter so I need to use: