Re: a Directory Crawler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ron,

I've got a function that does it for directories, and I've just quickly
modified it for you to do what you've stated, you can modify it if there is
a problem.

try this:


    $files = recurseDirectory("/home/mydir", null, null);

    foreach ($files as $i => $filename) {
        print "procesed $i $filename\n";
    }


//--------------------------------------------------------------------------
----
    function recurseDirectory($currentdir, $startdir=NULL, $files=array())

//--------------------------------------------------------------------------
----
    {
        chdir ($currentdir);
        // remember where we started from
        if (!$startdir) {
            $startdir = $currentdir;
        }
        $d = opendir (".");

        //list the files in the dir
        while ($file = readdir ($d)) {
            if ($file != ".." && $file != ".") {
                if (is_dir ($file)) {
                // If $file is a directory take a look inside
                    $files = $this->recurseDirectory(getcwd().'/'.$file,
getcwd(), $files);
                    //$files[] = $file; // add this if you want to output
dir name
                }
                else {
                // If $ file is not a directory then add it to our output
array
                    $files[] = $file;
                    if (strstr($file,".schema")) { // or u can use
preg_match if more comfortable
                        // fopen file etc etc, insert your code here
                    }

                }
            }
        }
        closedir ($d);
        chdir ($startdir);
        return $files;
    }

"Ron Herhuth" <Ron.Herhuth@tatumpartners.com> wrote in message
4e0c01c38122$76b60f60$f25d2981@tatumlink.com">news:4e0c01c38122$76b60f60$f25d2981@tatumlink.com...
I'm stuck.

I have been attempting to put together a script with little tidbits I've
found in the manual but I'm unable to figure out how to do this.

Basically I have a directory structure on my server that runs many levels
deep and wide.  In the directories there are several files with the
extension name ".schema"  I would like to have my script go through and
open each of these files (they are text files) and add the contents to a
variable which I will then store in a database.  I know how to display the
contents of a directory, as well as open and read text files...and write
to a database.  The problem I'm having is building the component that
traverses the directory structure pulling back all the files.  I can make
it read a single directory at a time but I'm at a loss to tell it how to
navigate through the directories.

This app is not for anything malicious, but I need a dynamic archive of
all the schemas and if I get brave I want to write an extraction tool to
extract the SQL queries from the schemas and catagorize them for future
use.

Thanks,
Ron

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux