Page 1 of 1

Ignoring directories

Posted: Fri May 26, 2006 6:24 am
by Life_eater
Hello!

I have this code for recursive scanning of a dir, but i don't want scan all dirs in a drive for example, and that's why i want to ignore some of them... but don't know how...

Code: Select all

function allFiles($path) {

  if (!is_dir($path))
     die("$path <<<<<< <b>WRONG DIRECTORY !!!</b>");
  if (!@dir($path))
     die("<br><br> Can't open directory <b>$path</b>, access or permission is denied !!!");
  $dir = dir($path);
  $path = $dir->path;
  while ($entry = $dir->read()) {
     $isDir = "$path/$entry";
     if (($entry != ".") && ($entry != "..")) $retAllFiles[] = $entry;
  };
  $dir->close();
  return $retAllFiles;
};
/* -=========== function recursive($path) ===========-
*/
function recursive($path) {
global $numFile , $numDir, $PATH, $DirAndFile;

  $result = allFiles($path);
  if (empty($result)) return;
  while (list ($value, $files) = each($result)) {
     if (is_dir("$path/$files")) {
        $numDir++;
        recursive("$path/$files");
     }
     else {
        $numFile++;
        $removePATH = str_replace($PATH, "", $path);        
        //$DirAndFile[$removePATH][] = "$files";
        $DirAndFile[$removePATH][$files] = filesize("$path/$files");
     };
  };
};
How to make this "directory-ignorer" and where in the code to put it?

I didn't write this code!

Thanks!

Posted: Fri May 26, 2006 6:47 am
by jayshields
Just change the function so you can pass an array of directory names to exclude to it.

Then when you open the dir to scan check if the name of it is in the array you passed to the function, if it's not, then proceed, if it is, skip the logging of the files.