http://www.php.net/manual/en/function.copy.php
Thanks all! I needed to check if pathname exists: if (!is_dir($to_path)) { echo "Creating destination path<br>"; create_path($to_path); } John Steele helped out with a few lines of code. I added a comment to http://www.php.net/manual/en/function.copy.php Here is the result: <? ####################################### $date = date ("Ymd"); ####################################### #$from_path = "c:\\tmp\\cp\\from"; $from_path = "c:/program files/easyphp/ccl_www"; $to_path = "c:/tmp/cp/to/$date/ccl_www"; ####################################### if (!is_dir($to_path)) { echo "Creating destination path<br>"; create_path($to_path); } ####################################### if(!is_dir($from_path)) { echo "failed"; exit; } else { rec_copy($from_path, $to_path); echo "Files copied from $from_path and backed up to $to_path\n"; } ######################################################################### function rec_copy($from_path, $to_path) { if (!is_dir($to_path)) # create_path($to_path); 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); } if (is_file($file)) { copy($from_path."\\".$file, $to_path."\\".$file); } } } closedir($handle); } else { echo "if (is_dir($from_path))<br>"; } } ############################################################ function create_path($to_path) { $path_array = explode('/', $to_path); // split the path by directories /* echo '<pre>'; // show everything in the $path_array variable var_dump($path_array); echo '</pre>'; */ $dir=''; // start with empty directory foreach($path_array as $key => $val) { // echo "$key => $val<br>"; if (!strpos($val, ':')) { // if it's not a drive letter $dir .= '/'. $val; if (!is_dir($dir)) { // echo "Not a dir: $dir<br>"; if (!mkdir($dir, 0777)) echo "Failed creating directory: $dir<br>"; else echo "Created directory: $dir<br>"; } } } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php