Folder::copy PHP Method

copy() public method

Copies the directory to a new location
public copy ( string $to ) : boolean
$to string
return boolean
    public function copy($to)
    {
        // Make destination directory
        $copy = new static($to);
        if (!$copy->make()) {
            return false;
        }
        // Loop through all subfiles and folders
        foreach ($this->content() as $item) {
            if (is_a($item, 'Folder')) {
                $dest = $to . DS . $item->name();
            } else {
                $dest = $to . DS . $item->filename();
            }
            if (!$item->copy($dest)) {
                return false;
            }
        }
        return $copy;
    }

Usage Example

Example #1
0
 /**
  * Make sure if the $appPath exists and copy the skel to there
  * @param string $appPath
  */
 public function initialAppPath($appPath)
 {
     App::uses('Folder', 'Utility');
     $fh = new Folder();
     if (file_exists($appPath)) {
         if (false === $fh->delete($appPath)) {
             $this->errorMessage = __('Target path exists. But the program could not delete the folder automatically');
             return false;
         } else {
             $this->tasks[] = array('title' => __('Target path exists. Delete the old folders.'), 'operactions' => $fh->messages());
         }
     }
     /*
      * Copy the skelecton of the application
      */
     $fh->copy(array('to' => $appPath, 'from' => VENDORS . 'olc_baker' . DS . 'skels' . DS . 'default', 'mode' => 0777));
     $errors1 = $fh->errors();
     $fh->copy(array('to' => $appPath . DS . 'cake2' . DS . 'lib', 'from' => CAKE_CORE_INCLUDE_PATH, 'mode' => 0777));
     $errors2 = $fh->errors();
     if (!empty($errors1) || !empty($errors2)) {
         $this->errorMessage = __('The program could not copy files to the folder automatically');
         return false;
     } else {
         $this->tasks[] = array('title' => __('Copy the skelecton of application to the target path'), 'operactions' => $fh->messages());
     }
     return true;
 }
All Usage Examples Of Folder::copy