|
Rob Thompsonrob.sun3.org |
$dir = "/Your/directory/here";
$extensions = array('.cfm','.html','.htm','.css','.php','.gif','.jpg','.png','.jpeg','.dwt');
$excludes = array('.svn');
<?
$findex = array();
$findex[path] = array();
$findex[file] = array();
$extensions = array('.cfm','.html','.htm','.css','.php','.gif','.jpg','.png','.jpeg','.dwt');
$excludes = array('.svn');
function rec_scandir($dir)
{
$files = array();
global $findex;
global $extensions;
global $excludes;
if ( $handle = opendir($dir) )
{
while ( ($file = readdir($handle)) !== false )
{
if ( $file != ".." && $file != "." )
{
if ( is_dir($dir . "/" . $file) )
{
$files[$file] = rec_scandir($dir . "/" . $file);
}
else
{
for ($i=0;$i<sizeof($extensions);$i++)
{
if (strpos(strtolower($file),strtolower($extensions[$i])) > 0)
{
$found = true;
}
}
for ($i=0;$i<sizeof($excludes);$i++)
{
if (strpos(strtolower($file),strtolower($excludes[$i])) > 0)
{
$found = false;
}
}
if ($found)
{
$files[] = $file;
$dirlink = $dir . "/" . $file;
array_push($findex[path],$dirlink);
array_push($findex[file],$file);
}
$found = false;
}
}
}
closedir($handle);
return $findex;
}
}
$dir = "/Your/directory/here";
echo "\n";
echo " Searching ". $dir ." for matching files\n";
$files = rec_scandir($dir);
echo " Found " . sizeof($files[file]) . " matching extensions\n";
echo " Scanning for orphaned files....\n";
$findex[found] = array();
for ($i=0;$i<sizeof($findex[path]);$i++)
{
echo $i . " ";
$contents = file_get_contents($findex[path][$i]);
for ($j=0;$j<sizeof($findex[file]);$j++)
{
if (strpos($contents,$findex[file][$j]) > 0)
{
$findex[found][$j] = 1;
}
}
}
echo "\n";
$counter=1;
for ($i=0;$i<sizeof($findex[path]);$i++)
{
if ($findex[found][$i] != 1)
{
echo " " . $counter . ") " . substr($findex[path][$i],0,1000) . " is orphaned\n";
$counter++;
}
}
?>
08/16/2007 08:36pm
This worked fine for me, with the following modifications:
added line: error_reporting(E_ERROR | E_WARNING | E_PARSE);
(to eliminate reporting of index not found)
$findex[path] -> $findex['path']
$findex[file] -> $findex['file']
$findex[found] -> $findex['found']
G
Write a comment
* = required field