On Jan 13, 2010, at 9:56 AM, Warren Windvogel wrote:

On 2010/01/13 04:25 PM, Rahul S. Johari wrote:

This is what I'm trying to do; I want to read a directory (eg: W: \Test\) and take all the filenames found in the directory (eg: 1.vox, 2.wav, 3.txt) and store them in a simple mySQL table.

Sorry. Forgot to include this.

function dirList ($directory)

   // create an array to hold directory list
   $results = array();

   // create a handler for the directory
   $handler = opendir($directory);

   // keep going until all files in directory have been read
   while ($file = readdir($handler)) {

       // if $file isn't this directory or its parent,
       // add it to the results array
       if ($file != '.' && $file != '..')
           $results[] = $file;

   // tidy up: close the handler

   // done!
   return $results;


If you're dealing with 1 directory you can use it to read all files in it to an array.

Kind regards

This is an interesting approach. Following is what I came up with to scan a directory and store the filenames into an array ... very similar to your example:

       $listDir = array();
        $dir = "../mounts/wd/IDT/IDT/";
        if($handler = opendir($dir)) {
            while (($sub = readdir($handler)) !== FALSE) {
if ($sub != "." && $sub != ".." && $sub != "Thumb.db") {
                    if(is_file($dir."/".$sub)) {
                        $listDir[] = $sub;
$listDir[$sub] = $this- >ReadFolderDirectory($dir."/".$sub);

and this is what I'm trying to implement in order to store the array into a mysql table ..

                        $db = mysql_connect("localhost","usr","pwd");
$colors=serialize($listDir); //takes the data from a post operation... $sql="INSERT INTO recordings (ID, RECORDING, ADDED) VALUES('','$colors','')";
                        $result = mysql_query($sql) or die (mysql_error());

I'm not sure if this the best or fastest approach ... but it's running in the background as I write this (I should have tested on a smaller folder). The folder I'm scanning has literally over 80,000 files ... so it's taking LOOONG!!

Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.

[Email] sleepwal...@rahulsjohari.com
[Web]   http://www.rahulsjohari.com

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to