Page 1 of 1

what's wrong in this function?

Posted: Tue Oct 18, 2005 3:31 am
by limonada
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
i wrote these functions for copying a directory tree and the files contained in it.the problem is that when i copy some directories,i also find in the first one the files from the current folder (the folder where the php script is).if somebody can look over the code...and tell me what's wrong....

Code: Select all

function copy_tree($path){	
		$f="xxx";		
		$dir=opendir(".");		
	    $f=readdir($dir); 
		
	    while ($f!="") {
	      if (is_dir($f)) {
			if (($f!=".") && ($f!="..")){  
	          chdir($f);
			 // echo $f."<br>";
			  $new_path = $path . "\\" . $f;
			  if(!is_dir($new_path)){
			   mkdir($new_path, 0777);
			  };
			  //echo $new_path . "<br>";	  
	          copy_tree($new_path); 
			  $str = realpath(".");
	          chdir(substr($str, 0, strrpos($str , "\\")));	  
	        }
	      }	  
	      $f=readdir($dir);
	      if (!is_dir($f) && ($f != "..") && ($f != "") && ($f != ".")){
			copy(realpath($f), "$path\\$f");
	      }
	    }
	    closedir($dir);
   }
   
   function copy_dir_content($from, $to){
         mkdir($to,0777);
		 chdir($from);
		 copy_tree($to);
   }
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Oct 18, 2005 5:04 am
by limonada
nevermind....it works :)