php-windows | 2001051

Re: [PHP-WIN] HELP: Print directory structure. From: Keith Ng (keith <email protected>)
Date: 05/15/01

In reply to alessio.bernesco <email protected>:

> Return-Path: <php-windows-return-7576-keith=k-designs.com.sg <email protected>>
> Received: from toye.php.net (va.php.net [198.186.203.51])
> by cobalt1.intermedia.com.sg (8.10.2/8.10.2) with SMTP id f4FE59Z12111
> for <keith <email protected>>; Tue, 15 May 2001 22:05:09 +0800
> Received: (qmail 18619 invoked by uid 1013); 15 May 2001 14:07:42 -0000
> Mailing-List: contact php-windows-help <email protected>; run by ezmlm
> Precedence: bulk
> list-help: <mailto:php-windows-help <email protected>>
> list-unsubscribe: <mailto:php-windows-unsubscribe <email protected>>
> list-post: <mailto:php-windows <email protected>>
> Delivered-To: mailing list php-windows <email protected>
> Received: (qmail 18613 invoked by uid 9); 15 May 2001 14:07:42 -0000
> To: php-windows <email protected>
> From: "Alessio Bernesco Lāvore" <alessio.bernesco <email protected>>
> Date: Tue, 15 May 2001 16:10:01 +0200
> Lines: 13
> Message-ID: <9drd7e$i5j$1 <email protected>>
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
> Subject: [PHP-WIN] HELP: Print directory structure.
> X-UIDL: _pi!!6+M"!']"#!:a&#!

> Could someone help me, please?

> I have to build a recursive function that print to video all the directories
> (and sub-directories and so on...) names presents in a specified
> sub-directory on the server.

> I can't handle that function, please, i'm in panic...

> Thanks,

> Alessio.

This simple and raw code should work fine:

<?
function parse_dir($dir,$level){
        print $dir." (DIR)<BR>\n";
        $dp=opendir($dir);
        while (false!=($file=readdir($dp))){
                if ($file!="." && $file!=".."){
                        if (is_dir($dir."/".$file)) parse_dir($dir."/".$file,$level+1);
                        else print $dir."/".$file."<BR>\n";
                }
        }
}

$start_dir="c:/root";
$level=1;

parse_dir($start_dir,$level);
?>

You could do some obvious modifications.
One impt thing to note is that the script might 'time out' if you are
listing a very huge list of dirs and files. To overcome this,
set_time_limit() might help. http://www.php.net/set_time_limit for
more info.

Hope that helps :)

Regards,
Keith Ng
_______________________________
Co-founder
K-Designs Incorporated
keith <email protected>

http://www.k-designs.com.sg/

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-windows-unsubscribe <email protected>
For additional commands, e-mail: php-windows-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>