Rename Directory Script

Rename directory scripts is used to move files and inside data one folder (Directory) to another folder.

Demo :




Example :

In the above demo folder icon is a old directory name and if you need to change that folder name you type name at New Directory Name text box and then click change button , now will be copied files from old folder to new folder.

Code :

Following code is use to Rename Directory script if you need code to copy and use to your website.


<?php
function copyRecursive($source, $destination)
{
  if (!file_exists($source))
  {
    die("'$source' is not valid");
  }
  if (!is_dir($destination))
  {
    mkdir ($destination);
  }
  $dh = opendir($source) or die ("Cannot open directory '$source'");
  while (($file = readdir($dh)) !== false)
  {
    if ($file != "." && $file != "..")
    {
    if (is_dir("$source/$file"))
  {
    copyRecursive("$source/$file", "$destination/$file");
  }
  else
  {
  copy ("$source/$file", "$destination/$file")or die ("Cannot copy file '$file'");
  }
  }
  }
  closedir($dh);
}
?>

In the above copyRecursive() function is used to move files or date one folder ( directory) to another folder. The file_exists(), is_dir() , mkdir(), opendir(), readdir(), copy(), closedir() has been used to inside of copyRecursive() function.

In the first function is a file_exists() and which function is used to check files available in server and second is_dir() function is used to check a directory or folder in a server and opendir() is used to open folder from server.

In the readdir() function is used to read a folder from server and copy () function is important function for a copyRecursive() and which function move files from one folder to another folder. The closedir() function is used to finally has used at copyRecursive() which function is used to close a folder at server.

Free Download Script :

If you need Rename Directory Script click and download from following link.

Download




Content