Forum Moderators: coopster

Message Too Old, No Replies

how to move content of folder

         

laura2k

10:48 pm on Feb 26, 2004 (gmt 0)



hi,

i have a folder that is constantly updated with content, I need to create a script that will move the entire content of that folder (not the folder, just the files in it) to another destination folder. I just cannot seem to find a function in php to deal with the moving of files within the server itself.

thanx in advance

jatar_k

11:58 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I didn't test this at all so be warned but it just might work

<? 
$mydir = "/path/to/dir/";
$destdir = "/path/to/new/dir/";
$d = dir [ca.php.net]($mydir);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
$oldpath = $mydir . $entry;
$newpath = $destdir . $entry;
$success = copy [ca.php.net]($oldpath,$newpath);
if ($success) unlink($oldpath);
else die("There was an error copying $oldpath");
}
}
$d->close();
?>