d22552000 Posted August 13, 2007 Share Posted August 13, 2007 soo.. how do I do it? copy only copies ONE file... I want to copy a folder, subfolder, files, and subfiles. I don't care about attributes. I thought about making the folder a zip, and then using extract but that was confusing and took too long on the server. so what do I do? Is there a script that will parse the dir and COPY all the files? Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/ Share on other sites More sharing options...
Noggin Posted August 13, 2007 Share Posted August 13, 2007 I'm not sure on a script, but selecting all files in a folder, I'm guessing, would have something to do with 'directory\*.*' Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322384 Share on other sites More sharing options...
d22552000 Posted August 13, 2007 Author Share Posted August 13, 2007 Yes this would select all files in THAT folder... but not subfolders. and with over 90 subfolders I don't want to list them all. This would also make my php file reallly big -,-. Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322389 Share on other sites More sharing options...
Noggin Posted August 13, 2007 Share Posted August 13, 2007 I can understand where you're coming from, I have the same sort of problems I'm sorry I can't provide more help, unless it's possible to use 'directory\*\' Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322390 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 unction COPY_RECURSIVE_DIRS($dirsource, $dirdest) { // recursive function to copy // all subdirectories and contents: if(is_dir($dirsource))$dir_handle=opendir($dirsource); mkdir($dirdest."/".$dirsource, 0750); while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirsource."/".$file)) copy ($dirsource."/".$file, $dirdest."/".$dirsource."/".$file); else COPY_RECURSIVE_DIRS($dirsource."/".$file, $dirdest); } } closedir($dir_handle); return true; } Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322393 Share on other sites More sharing options...
PhaZZed Posted August 13, 2007 Share Posted August 13, 2007 This will probably help.. function copyr($source, $dest){ // Simple copy for a file if (is_file($source)) { $c = copy($source, $dest); chmod($dest, 0777); return $c; } // Make destination directory if (!is_dir($dest)) { $oldumask = umask(0); mkdir($dest, 0777); umask($oldumask); } // 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; } Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322398 Share on other sites More sharing options...
d22552000 Posted August 13, 2007 Author Share Posted August 13, 2007 YAY!! thank you.. I will try it before I say if its solved or not... $d = "C:/Inetpub/wwroot/" . $_CUSTOMER['path'] . "/forum"; $s = "C:/Inetpub/installers/forum"; COPY_RECURSIVE_DIRS($s,$d); function COPY_RECURSIVE_DIRS($dirsource, $dirdest) { // recursive function to copy // all subdirectories and contents: if(is_dir($dirsource))$dir_handle=opendir($dirsource); mkdir($dirdest."/".$dirsource, 0750); while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirsource."/".$file)) copy ($dirsource."/".$file, $dirdest."/".$dirsource."/".$file); else COPY_RECURSIVE_DIRS($dirsource."/".$file, $dirdest); } } closedir($dir_handle); return true; } Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322401 Share on other sites More sharing options...
d22552000 Posted August 13, 2007 Author Share Posted August 13, 2007 Problem: no matter how I do a full path it wont take it because of the special uses of \... $filename = "C:/Inetpub\wwwroot\"; $filename = $filename . $p; $filename = $filename . "\forum\includes\config.php"; give me: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\Inetpub\wwwroot\* on line 36 Parse error: syntax error, unexpected T_STRING in C:\Inetpub\wwwroot\* on line 36 Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322420 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 Use / NOT \ Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322426 Share on other sites More sharing options...
d22552000 Posted August 13, 2007 Author Share Posted August 13, 2007 lol then I get a different erorr, tried that. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\wwwroot\Registration\vbcreate.php on line 38 It doenst expect the $p variable cause the first line: $filename = "C:/Inetpub/wwwroot/"; doesnt close if I have a / and then a quote. The / denotes to escape the " -,-. Got any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322431 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 humm sounds like a messed up path, delete the whole line and retype Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322455 Share on other sites More sharing options...
d22552000 Posted August 13, 2007 Author Share Posted August 13, 2007 tried that. the path is full. the path comes up perfect elsewhere... and $p is just a folder claled test.. but I need to keep it a variable casue its dynamic. $filename = "C:/Inetpub/wwwroot/" . $p . "/forum/includes/config.php"; Quote Link to comment https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322543 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.