Re: HELP: Print directory structure.
| From: | Keith Ng | Date: | Tue, 15 May 2001 14:22:37 +0000 |
| Subject: | Re: HELP: Print directory structure. | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-7577@lists.php.net to get a copy of this message | ||
In reply to alessio.bernesco@dinemacomputer.it:
> Return-Path: <php-windows-return-7576-keith=k-designs.com.sg@lists.php.net>
> 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@k-designs.com.sg>; 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@lists.php.net; run by ezmlm
> Precedence: bulk
> list-help: <mailto:php-windows-help@lists.php.net>
> list-unsubscribe:
> <mailto:php-windows-unsubscribe@lists.php.net>
> list-post: <mailto:php-windows@lists.php.net>
> Delivered-To: mailing list php-windows@lists.php.net
> Received: (qmail 18613 invoked by uid 9); 15 May 2001 14:07:42 -0000
> To: php-windows@lists.php.net
> From: "Alessio Bernesco Làvore" <alessio.bernesco@dinemacomputer.it>
> Date: Tue, 15 May 2001 16:10:01 +0200
> Lines: 13
> Message-ID: <9drd7e$i5j$1@toye.p.sourceforge.net>
> 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@k-designs.com.sg
http://www.k-designs.com.sg/