Jump to content

Scanning A Directory


tarun

Recommended Posts

Hi Tarun...

 

Here is a piece of code i had used earlier in one of my scripts

 


function get_dir($path,$max_depth='',$l=0,$total=''){
global $conn;
global $desireddir, $host, $mod;
   if(!is_dir($path))return;
   $path=substr($path,-1)!="/"?$path."/":$path;
   if(!$l){
       $total=0;
   }
   if($max_depth==='' || ($max_depth>$l && is_int($max_depth))) $test_depth=true;
   else $test_depth=false;
   $pre="";
   $c=$l;
   while($c--)$pre.="    ";
   $dir=opendir($path);
   while($f=readdir($dir)){
       if($f=="."||$f=="..")continue;
       $file=$path.$f;
       $size="";
   if(is_dir($file))
   {
   		$newdir = $desireddir . str_replace("upload", "", $file);
   		ftp_mkdir($conn, $newdir);
		if(strpos(ftp_pwd($conn), "wp-content") || strpos($newdir, "wp-content"))
			{
				ftp_site($conn, 'CHMOD '.$mod.' '. $newdir);
			}

   }
       if((is_file($file)||!is_dir($file)) && (substr($file, strlen($file)-3) == "php"){
                       // DO WHAT YOU WANT TO WITH THE FILE....
           }
       else $f.="/";
       while(strlen($size)<16)
           $size=" ".$size;
       if(is_dir($file) && $test_depth)
           $total=get_dir($file,$max_depth,$l+1,$total);
   }
   if(!$l)
   return $total;
}

Link to comment
https://forums.phpfreaks.com/topic/48125-scanning-a-directory/#findComment-235246
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.