Ignoring directories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Life_eater
Forum Newbie
Posts: 1
Joined: Wed Jan 25, 2006 6:49 am

Ignoring directories

Post 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!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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.
Post Reply