Copy/Move Complete Directory Structure in PHP

Hi Everyone…

Following is the function which to copy the compete directory structure from source to destination. This function was used extensively by me in my final year project…

function GetContents (&$noOfFiles, &$noOfDir, $sourceDirectory)
         $delim = DIRECTORY_SEPARATOR;
         $tempCWD = $sourceDirectory;
         @chdir ($tempCWD);
         $Contents = Array();
         $dirPtr = dir (getcwd());
         while ($file = $dirPtr->read())
             if ($file != "." && $file != ".." && is_dir($file) && $file{0} != "." && $file != "trash")
                 $Contents[] = $file;
             else if ($file != "." && $file != ".." && is_file($file) && $file{0} != ".")
                 $Contents[] = $file;
         return @$Contents;

4 Responses to “Copy/Move Complete Directory Structure in PHP”

  1. personalized baby blankets, Says:

    Good info. Lucky me I discovered your blog by accident
    (stumbleupon). I have saved it for later!

  2. otaxige Says:

    move folder:


    $oldfolderpath = “old/old_folder_name”;
    $newfolderpath = “new/new_folder_name”;


  3. เนอร์สซิ่งโฮม Says:

    I really like reading an article that will make people think.

    Also, thanks for allowing for me to comment!

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: