AW: a Directory Crawler

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

 



Hi Ro,
how about this snippet ? 

<?PHP

function Check_For_Final_Slash($path) {

   if (substr($path, (strlen($path) - 1), 1) != "\\") {
      $path = $path . "\\";
   }
   return($path);
}

// $path: input the topmost folder to be searched
function Get_Directory_Listing($path) {

   $path = Check_For_Final_Slash($path);
   if ($dir_handle = opendir($path)) {
      while ($file = readdir($dir_handle)) {
         chdir($path);
         if ($file != "..") {
            if (($file != ".")) {
               if (is_dir($file)) {
                  chdir($path . $file);
			   
                  // in this case, I make up a HTML page with refs; you would call Get_Directory_Listing($path . $file) recursively here
                  print("<FORM NAME='CHANGE_DIR' ACTION='index.html' METHOD='POST'>");
                  print("<INPUT TYPE='HIDDEN' NAME='PATH' VALUE='" . $path . $file . "'>");
                  print("<A HREF='#' onClick='submit();' >" . $file . "</A></INPUT>");
                  print("</FORM>");
               }
            }
            else {
               // up one step; you would probably leave out this branch
               $file = substr($path, 0, strrpos(substr($path, 0, strlen($path) - 1), "\\"));
               print("<FORM NAME='CHANGE_DIR' ACTION='index.html' METHOD='POST'>");
               print("<INPUT TYPE='HIDDEN' NAME='PATH' VALUE='" . $file . "'>");
               print("<A HREF='#' onClick='submit();' >[ up one level ]</A></INPUT>");
               print("</FORM>");
            }
         }
      }
      closedir($dir_handle);
   }
   if ($dir_handle = opendir($path)) {
      while ($file = readdir($dir_handle)) {
         $path = Check_For_Final_Slash($path);
         chdir($path);
         if (($file != ".") && ($file != "..")) {
            if (is_file($file)) {
	    
               // here comes the action; I spit out a handle, you may open, read end extract
               print("<A HREF='" . $path . $file . "'>" . $file . "</A><BR>");
            }
         }
      }
      closedir($dir_handle);
   }
}
?>
-- 
Sven Schnitzke

> -----Ursprüngliche Nachricht-----
> Von:	Herhuth, Ron [SMTP:Ron.Herhuth@tatumpartners.com]
> Gesendet am:	Montag, 22. September 2003 17:59
> An:	php-windows@lists.php.net
> Betreff:	 a Directory Crawler
> 
> 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

-- 
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