The code contains two functions. You need to run the MoveDirectory function pass it the source and destination directories. If copy is set to false the origional dir is removed. If it is set to true the origional dir is not deleted.
By : metcarob
function MoveDirectory($source,$dest,$copy=false) { //remove trailing slashes if (substr($dest,-1) == "\\") $dest = substr($dest,0,strlen($dest)-1); if (substr($source,-1) == "\\") $source = substr($source,0,strlen($source)-1); if (!file_exists($source)) return FALSE;
Ensure_Sub_Directory_Exists($dest);
//now copy all the files & direcrtories to the new location and deltet them $d = opendir($source); while ($f = readdir($d)) { $l = $source . "\\" . $f; if (is_dir($l)) { if (!($f['value']=="." || $f=="..")) { MoveDirectory($l,$dest . "\\" . $f,$copy); }; } else { copy( $l ,$dest . "\\" . $f); if (!$copy) { //we are moving the directory so we should delete the file unlink($l); }; }; }; closedir($d); if (!$copy) { rmdir($source); }; return TRUE; }; function Ensure_Sub_Directory_Exists($dir) { //When passed a directory create it if (substr($dir,-1) == "\\") $dir = substr($dir,0,strlen($dir)-1);
//does $b exist? if (!file_exists($b)) { Ensure_Sub_Directory_Exists($b); }; //PArent exists so make this directork exist mkdir($dir); return TRUE; };
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.