what's wrong in this function?

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
limonada
Forum Newbie
Posts: 11
Joined: Sat Oct 08, 2005 7:23 am

what's wrong in this function?

Post 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]
limonada
Forum Newbie
Posts: 11
Joined: Sat Oct 08, 2005 7:23 am

Post by limonada »

nevermind....it works :)
Post Reply