This is simple function to move a complete directory to another location. Currently, it only can move directories with files, not with sub-directories. New version with lot more featuers coming soon!
By : CodeKadiya
<?php ########################### # Move Directory Function # # Written by : CodeKadiya # ###########################
$newDir="c:\dirnew"; // Destination to move $oldDir="c:\dirold"; //Dir to move dirmove($oldDir,$newDir);
function dirmove($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); } ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.