Getting Partial Dir Path

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
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Getting Partial Dir Path

Post by eggoz »

I wrote a script that list all dirs inside a folder, including subdirectories. After I was done,
I realized this wasn't excatly what I was looking for. Here is my code:

Code: Select all

<?php
function RecurseDir($basedir, $AllDirectories=array()) {
        #Create array for current directories contents
        $ThisDir=array();
        #switch to the directory we wish to scan
        chdir($basedir);
        $current=getcwd();
        #open current directory for reading
        $handle=opendir(".");
        while ($file = readdir($handle)) {
                #Don't add special directories '..' or '.' to the list
                if (($file!='..') & ($file!='.')) {
                        if (is_dir($file)) {
                                #build an array of contents for this directory
                                array_push($ThisDir,$current.'/'.$file);
                        }
                }
        }
        closedir($handle);
        #Loop through each directory,  run RecurseDir function on each one
        foreach ($ThisDir as $key=>$var) {
                array_push($AllDirectories, $var);
                $AllDirectories=RecurseDir($var, $AllDirectories);
        }
        #make sure we go back to our origin
        chdir($basedir);
        return $AllDirectories;
}
?>

<?
$dirlist=RecurseDir("/var/www/html/Pictures/pictures/Olympus Camedia/");
foreach ($dirlist as $key=>$val) {
//    echo $val;
//	$up_dir = chdir(../$val);
	$all_dir = basename($val);
	print "$all_dir <br>";
}
?>
I am not expecting anybody to write to the script, but just some ideas on how this could be
done using this script. I need it to display Folder/Sub_Folder (if one exsists). For example...

Diego
Army Pals
Class
carwash

Where the link would point to...

Diego
Diego/Army Pals
Diego/Class
carwash

I don't even know how to begin this idea... Thanks.
Post Reply