PHP – Directory Mover

The given PHP example can move a directory from one location to another location.

Code Example:
<?php
$newDir="d:\dirnew"; // Destination to move 
$oldDir="c:\dirold"; //Dir to move 
dirmover($oldDir,$newDir); 

function dirmover($oldDir,$newDir){ 
@rmdir($newDir); 
@mkdir($newDir) or die("Directory already exists."); 
$dir=@opendir($oldDir) or die("Invalid directory."); 
while($file=@readdir($dir)) 
{ 
    if(($file!='.') && ($file!='..')) 
    { 
        @copy($oldDir."\\".$file,$newDir."\\".$file) or die("Unable to copy file :$file."); 
        @unlink($oldDir."\\".$file) or die("Unable to remove file :$file."); 
    } 
} 
@closedir($dir); 
@rmdir($oldDir); 
} 
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *