rec_copy

From: Date: Thu, 14 Mar 2002 03:37:41 +0000
Subject: rec_copy
Groups: php.general 
Request: Send a blank email to php-general+get-88424@lists.php.net to get a copy of this message
You might have seen a version of this function: http://www.php.net/manual/en/function.copy.php I would like to rework this line: mkdir($to_path, 0777); where mkdir will ignore $to_path if the directory already exists. I have already tried this: #if(!mkdir($to_path, 0777)) # {mkdir($to_path, 0777);} but that doesn't work. I suppose that is because the function calls itself when it creates sub-directories. Any ideas? John ##########------- snip --------#################### $date = date ("Ymd"); rec_copy($from_path, $to_path); echo "files copies from $from_path and backed up to $to_path"; function rec_copy ($from_path, $to_path) { mkdir($to_path, 0777); #if(!mkdir($to_path, 0777)) # {mkdir($to_path, 0777);} $this_path = getcwd(); if (is_dir($from_path)) { chdir($from_path); $handle=opendir('.'); while (($file = readdir($handle))!==false) { if (($file != ".") && ($file != "..")) { if (is_dir($file)) { rec_copy ($from_path.$file."/", $to_path.$file."/"); chdir($from_path); }else{ # echo "error if (is_dir($file))<br>"; } if (is_file($file)) { copy($from_path.$file, $to_path.$file); }else{ # echo "error copy($from_path.$file, $to_path.$file)<br>"; } }#end (($file != ".") }#end while (($file closedir($handle); }# end if (is_dir else{ echo "if (is_dir($from_path))<br>"; } }# end function

« previous php.general (#88424) next »