dos tree

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

dos tree

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: dos tree

Post by requinix »

So why not just do the same thing using PHP code?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: dos tree

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: dos tree

Post by Celauran »

Depends on how your site is structured. Is it front controlled or a bunch of page scripts?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: dos tree

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: dos tree

Post by Celauran »

User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: dos tree

Post 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:

Code: Select all

$_SERVER["DOCUMENT_ROOT"]
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply