aximbigfan Posted September 22, 2008 Share Posted September 22, 2008 I have this code (Thanks Aidan Lister!) function copyr($source, $dest) { // Simple copy for a file if (is_file($source)) { return copy($source, $dest); } // Make destination directory if (!is_dir($dest)) { mkdir($dest); } // If the source is a symlink if (is_link($source)) { $link_dest = readlink($source); return symlink($link_dest, $dest); } // Loop through the folder $dir = dir($source); while (false !== $entry = $dir->read()) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Deep copy directories if ($dest !== "$source/$entry") { copyr("$source/$entry", "$dest/$entry"); } } // Clean up $dir->close(); return true; } Say I have this dir /Test1/Test2/Test3/ Say I try to copyr("/Test1/Test2/", "/Test1"); The end result is that nothing happens. No errors. Literally, nothing. Anyone see any reason for this to be happening? It does NOT happen when I copyr("/Test1/Test2", "/otherdir/"); Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/ Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 it copies over itself.. what would you expect it to do? Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647462 Share on other sites More sharing options...
aximbigfan Posted September 22, 2008 Author Share Posted September 22, 2008 Is there any way to fix it? Recursive/loop stuff is not my strong point.. Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647473 Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 what did you expect it to do? it copied the dir... it replaced itself, but it still copied the dir... so it did exactly what you asked. Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647480 Share on other sites More sharing options...
aximbigfan Posted September 22, 2008 Author Share Posted September 22, 2008 It should have just copied like this: copyr("/Test/1/2/3", "/Test/"); The end result being /Test/whatever-is-in-3 Chris Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647484 Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 Ah, you want it to just copy the contents of the destination dir, whereas right now it is copying the destination dir as well as its contents... is that correct? Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647488 Share on other sites More sharing options...
aximbigfan Posted September 22, 2008 Author Share Posted September 22, 2008 No, I do want it to copy the actual dir itself too. Sorry, I messed that example up.. Chris Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647493 Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 So you want it to rename the copied directory if it already exists and copy it under a new name? Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647495 Share on other sites More sharing options...
aximbigfan Posted September 22, 2008 Author Share Posted September 22, 2008 It _should_ just copy to the same dir. IE I have this /1/2/3 if I copy /1/2/3 to /1, I would like the path outcome to be /1/3 Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647499 Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 Ah, and what is it doing currently? my quick overlook of the code says it should be doing that already. Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647501 Share on other sites More sharing options...
aximbigfan Posted September 22, 2008 Author Share Posted September 22, 2008 It doesn't do anything. The dir never gets copied to the new location. EDIT: It WILL copy under certain conditions. Say i want to copy /dir/dir1/dir2 to /dir1/x . That will work. Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/125249-strange-copy-problem/#findComment-647503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.