Location: PHPKode > scripts > Find files > twzFindFiles_obfus.php
<?php

// twzFindFiles.php


$Filename        = 'php.ini';
$TopFolder       = '../';
$RecurseLevel    = 5;

$MaxFilenameSize = 20; // used for spacing
$ExactName       = true;
$ExactCase       = true;


/*

    twzFindFiles.php

    This script searches for files by name, and lists them by directory 
    showing filename, permissions, date modified and file size.

    Copyright © tweezy.net.au 2009
    For enquiries please contact hide@address.com
    
    -------------------------------------------------------------------
    
    SETTINGS

    $Filename ......... name of file(s) to locate. Can be a string or an array
                        of strings, eg $Filename = array('.htaccess', 'php.ini');
    $TopFolder ........ the directory to start the search. 
                        For example, use './' for the directory containing this script, 
                        or '../' for the directory above.
    $RecurseLevel ..... depth of directory search. 
                        If zero, only the $TopFolder will be searched. 
                        For "infinite" recursion (all folders), use a big number, eg 999.
    $MaxFilenameSize .. used only for spacing the output. 
                        Filenames longer than this will still be shown, but their
                        details will not be aligned with other files listed.
    $ExactName ........ if true, files must exactly match $Filename. 
                        If false, results will include all filenames that contain $Filename.
    $ExactCase ........ if false, filenames will match regardless of upper/lower case letters.

*/



//________________________________________
// do not edit below here
if(is_string($Filename)) $Filename=array($Filename); $RegexMeta='^$.[]|()?*+{}'; $meta1=array(); $meta2=array(); for($i=0; $i<strlen($RegexMeta); $i++) { $meta1[]=$RegexMeta[$i]; $meta2[]=chr(92).$RegexMeta[$i]; } $FilenamesEscaped=str_replace($meta1, $meta1, $Filename); $FileSpec='('.implode('|', $FilenamesEscaped).')'; $FileSpec=($ExactName) ? "/^$FileSpec$/" : "/$FileSpec/"; if(!$ExactCase) $FileSpec.='i'; $Found=FileListRX($TopFolder, $FileSpec, 'full', $RecurseLevel); echo "<pre>\r\n"; $Heading='Searching for files: '.FormatArray($Filename); echo $Heading."\r\n".str_repeat("_", strlen($Heading))."\r\n\r\n"; $FileCount=0; foreach($Found as $Folder=>$FileInfo) { echo "\r\n$Folder\r\n"; foreach($FileInfo as $ThisFilename=>$FileAttrib) { echo '   '.str_pad($ThisFilename, $MaxFilenameSize).'  '.$FileAttrib['perm'].'  '.$FileAttrib['date'].'  '.FormatFileSize($FileAttrib['size'])."\r\n"; $FileCount++; } } $Footing=$FileCount.' files found'; echo "\r\n".str_repeat("_", strlen($Footing))."\r\n$Footing\r\n"; echo "</pre>\r\n";
function FileListRX($vTWZ1, $vTWZ2='', $vTWZ3='', $vTWZ4=0, $vTWZ5=array(), $vTWZ6=false, $vTWZ7=0) { if(substr($vTWZ1,-1)<>'/') $vTWZ1="$vTWZ1/"; if($vTWZ7<=0) $vTWZ7=0; if(''==$vTWZ2) $vTWZ2='/.*/'; $vTWZ8=array(); if (@$vTWZ9 = opendir($vTWZ1)) { while (false !== ($vTWZ10=readdir($vTWZ9))) { if ($vTWZ10 != "." and $vTWZ10 != "..") { if(is_dir($vTWZ1.$vTWZ10) and $vTWZ7<$vTWZ4 and ($vTWZ6 or !is_link($vTWZ1.$vTWZ10)) and !in_array($vTWZ1.$vTWZ10, $vTWZ5) ) { $vTWZ8=array_merge( $vTWZ8, FileListRX(($vTWZ1.$vTWZ10), $vTWZ2, $vTWZ3, $vTWZ4, $vTWZ5, $vTWZ6, ($vTWZ7+1)) ); } elseif(is_file($vTWZ1.$vTWZ10) and preg_match($vTWZ2, $vTWZ10, $vTWZ11)) { $vTWZ12=date('Y-m-d H:i:s',filemtime($vTWZ1.$vTWZ10)); $vTWZ13=filesize($vTWZ1.$vTWZ10); $vTWZ14=substr(decoct(fileperms($vTWZ1.$vTWZ10)), -3); switch($vTWZ3) { case 'full': $vTWZ8[$vTWZ1][$vTWZ10]['size']=$vTWZ13; $vTWZ8[$vTWZ1][$vTWZ10]['date']=$vTWZ12; $vTWZ8[$vTWZ1][$vTWZ10]['perm']=$vTWZ14; break; case 'simple': default: $vTWZ8[]=$vTWZ1.$vTWZ10; } } } } closedir($vTWZ9); } return $vTWZ8; } 
function FormatFileSize($vTWZ15) { if(!is_numeric($vTWZ15)) return $vTWZ15; if ($vTWZ15<1000) return ($vTWZ15.' bytes'); elseif ($vTWZ15<1000000) return (number_format($vTWZ15/1024, 1).' KB'); elseif ($vTWZ15<1000000000) return (number_format($vTWZ15/1024/1024, 1).' MB'); else return number_format($vTWZ15/1024/1024/1024, 1).' GB'; } 
function FormatArray($vTWZ16, $vTWZ17=false, $vTWZ18=', ', $vTWZ19=' => ') { $vTWZ20=''; $vTWZ21=strlen($vTWZ18); foreach($vTWZ16 as $vTWZ22 => $vTWZ23) { $vTWZ20.=($vTWZ17) ? $vTWZ22.$vTWZ19.$vTWZ23.$vTWZ18 : $vTWZ23.$vTWZ18; } if($vTWZ20<>'') $vTWZ20=substr($vTWZ20,0,-$vTWZ21); return $vTWZ20; }

?>
Return current item: Find files