Re: Get directory items, read file lines...
| From: | Robert Cummings | Date: | Thu, 22 Aug 2002 15:49:38 +0000 |
| Subject: | Re: Get directory items, read file lines... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-113640@lists.php.net to get a copy of this message | ||
Hmmm it's been working fine for me, but thanks, I'll update the code
I ripped this from.
Cheers,
Rob.
------------------------------------------------------------------------
Richard Black wrote:
>
> You need to check the TYPE of the return value from readdir, because a
> filename that evaluates to fals will stop the loop.
>
> So you need
>
> while ( ($aFile = @readdir( $dir ) ) !== false)
> {
> // Stuff in here
> }
>
> It's in the manual page...
>
> Richy
> ==========================================
> Richard Black
> Systems Programmer, DataVisibility Ltd -
> http://www.datavisibility.com
> Tel: 0141 435 3504
> Email: rblack@datavisibility.co.uk
>
> -----Original Message-----
> From: robert.cummings@webmotion.com
> [mailto:robert.cummings@webmotion.com]
> Sent: 22 August 2002 16:38
> To: Joseph W. Goff
> Cc: php-general; Bill Leonard
> Subject: Re: [PHP] Get directory items, read file lines...
>
> Here you go...
>
> if( ($dir = @opendir( $path )) )
> {
> while( $aFile = @readdir( $dir ) )
> {
> //
> // Test you really have a file vs. having a
> // directory and then do your stuff.
> //
> }
> }
>
> A far better approach though, is to familiarize yourself with the
> appropriate routines:
>
> http://www.php.net/manual/en/ref.dir.php
> http://www.php.net/manual/en/function.file.php
>
> Cheers,
> Rob.
--
.-----------------.
| Robert Cummings |
:-----------------`----------------------------.
| Webdeployer - Chief PHP and Java Programmer |
:----------------------------------------------:
| Mail : mailto:robert.cummings@webmotion.com |
| Phone : (613) 731-4046 x.109 |
:----------------------------------------------:
| Website : http://www.webmotion.com |
| Fax : (613) 260-9545 |
`----------------------------------------------'