move directory in php


<?php

function moveDir($dir,$dest) {
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “..”) {
if(is_dir($dir.’/’.$file)) {
$dir2 = $dir.’/’.$file;
$dest2 = $dest.’/’.$file;
@mkdir($dest.’/’.$file);
getFilesFromDir($dir2, $dest2);
rmdir($dir.’/’.$file);
}
else {
rename($dir.’/’.$file,$dest.’/’.$file);
}
}
}
closedir($handle);
}
if(is_dir($dir))
@rmdir($dir);
}

$source = ‘apple’;

$dest = ‘back’;

moveDir($source, $dest);

?>

Advertisements
Posted in php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s