RE: [PHP] Get directory items, read file lines...

From: Date: Thu, 22 Aug 2002 15:42:11 +0000
Subject: RE: [PHP] Get directory items, read file lines...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-113638@lists.php.net to get a copy of this message
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. ------------------------------------------------------------------------ --- "Joseph W. Goff" wrote: > > 1) readdir(); > > 2) $your_file = file($filename); > $your_line=$your_file[$your_line_number] > > 3) $fp = fopen($filename,'w'); > fputs($fp,$your_text); > fclose($fp); > > In the second argument to fopen, w = write, a = append, r = read See > the manual for more info on these functions. > ----- Original Message ----- > From: "Bill Leonard" <bill@machinemen.com> > To: <php-general@lists.php.net> > Sent: Thursday, August 22, 2002 10:15 AM > Subject: [PHP] Get directory items, read file lines... > > > Hey all, > > > > Pretty new to PHP... A couple of general questions will help me > > solve a larger problem...! > > > > 1) I need to read all of the names of the files in a given directory > > > > 2) read a given line number out of each of these files (just text) > > > > 3) write it to a delimited file of some sort > > > > I think I am on to #2 and #3, but #1 I am having trouble with... Any > > pointers would be appreciated! -- .-----------------. | 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 | `----------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#113638) next »