Re: Building a list of filenames (w2k)

From: Date: Fri, 08 Feb 2002 15:29:13 +0000
Subject: Re: Building a list of filenames (w2k)
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-11918@lists.php.net to get a copy of this message
Forgive me if I slip up ... this line from the code example below: $result_array =a rray(); There should be no space in the word array(); Should look like this: $result_array = array(); ** sorry about that !! Some other fixes too .... here's the code again: ---------------------------- <snip> function list_dir($dirname) { $result_array = array(); $handle = opendir( $dirname ); while ( $file = readdir( $handle ) ) { if( $file == '.' || $file == '..' ) continue; if( is_dir( "$dirname\\$file" ) ) { list_dir( "$dirname\\$file" ); ## recursion; gets subdirectories } else { $result_array[] = "$dirname\\$file"; } } closedir($handle); return $result_array; } </snip> --------------------------------------------------------- -nicole www.aeontrek.com "Nicole Amashta" <430ntr3k@bellsouth.net> wrote in message news:20020208152411.30449.qmail@pb1.pair.com... > I suggest checking the php.net site for doing this. You can use their search > box to search on particular subjects of PHP. For example, what you want to > do involves files and directories. YOu want to read from a directory and > list the files. So, on php.net, in the search box, you can type: dir and it > will take you to the appropriate documentation (of course, you may not > already know that, so you can't find the documention. > > Anyway, here's a link to useing directories: > http://www.php.net/manual/en/ref.dir.php > > and if you want to deal directly with files, here's a link for doing that: > http://www.php.net/manual/en/function.file.php > > Below is sample code I just copied and pasted, and slightly modified, from > the 1st link. It's an example of listing the files in a directory and > returning them in an array. > > ====================================== > ## $dirname is the path of the directory you want to list files from. > > function list_dir($dirname) > { > $result_array =a rray(); > $handle = opendir( $dirname ); > > while ( $file = readdir( $handle ) ) > { > if( $file == '.' || $file == '..' ) > continue; > > if( is_dir( $dirname.$file ) ) { > list_dir( $dirname.$file ); ## recursion; gets subdirectories > } > else { > $result_array[] = $dirname.$file; > } > } > > closedir($handle); > > return $result_array; > > } > > > ================================ > > "George Pitcher" <fmdev@yahoo.co.uk> wrote in message > news:027c01c1b091$0214ab20$630db092@HLATITUDE... > > Hi all, > > > > I want to build a list of filenames from a particular directory. I can't > > find anything like this in the manual or on the list archive so any > pointers > > would be appreciated. > > > > George > > > >

« previous php.windows (#11918) next »