method rename documentation in bbn\Ide\Directories

Renames a file or a directory.

function($dir, $path, $new, $type = 'file') { ($root = $this->getRootPath($dir)) && bbn\Str::checkFilename($new) ){ $is_file = $type === 'file'; $wtype = $is_file ? 'file' : 'directory'; $pi = X::pathinfo($path); $files = []; if ( $pi['filename'] !== $new ){ if ( !empty($cfg['tabs']) ){ $ext = false; foreach ( $cfg['tabs'] as $t ){ if ( empty($t['fixed']) ){ // MVC tab's path $real = $root . $t['path']; if ( $pi['dirname'] !== '.' ){ $real .= $pi['dirname'] . '/'; } if ( $is_file ){ foreach ( $t['extensions'] as $e ){ $real_new = $real . $new . '.' . $e['ext']; $real_ext = $real . $pi['filename'] . '.' . $e['ext']; if ( file_exists($real_ext) ){ if ( !file_exists($real_new) ){ $ext = empty($ext) ? $e['ext'] : $ext; $files[$real_ext] = $real_new; if ( $t['url'] === 'php' ){ $change_perm = [ 'old' => $real_ext, 'new' => $real_new, 'type' => 'file' ]; } } else { $this->error("The file $real_new is already exists."); return false; } } } if ( !empty($t['default']) ){ $file_url = $this->realToUrl($real_ext); $file_new_url = $this->realToUrl($real_new); } } else { $real_new = $real . $new; $real .= $pi['filename']; if ( file_exists($real) ){ if ( !file_exists($real_new) ){ $files[$real] = $real_new; if ( $t['url'] === 'php' ){ $change_perm = [ 'old' => $real, 'new' => $real_new, 'type' => 'dir' ]; } } else { $this->error("The directory $real_new is already exists."); return false; } } } if ( !empty($t['default']) ){ $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new; $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new; } } } } else { $real = $root . $path; $real_new = $root . $new . ($is_file ? '.' . $pi['extension'] : ''); if ( file_exists($real) ){ if ( !file_exists($real_new) ){ $files[$real] = $real_new; } else { $this->error("The $wtype $real_new is already exists."); return false; } if ( $is_file ){ $file_url = $this->realToUrl($real); $file_new_url = $this->realToUrl($real_new); $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension']; $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension']; } else { $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new; $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new; } } } foreach ( $files as $s => $d ){ if ( !rename($s, $d) ){ $this->error("Impossible to rename the $wtype: $s -> $d"); return false; } if ( is_file($s) ){ // Remove file's options $this->options->remove($this->options->fromCode($this->realToId($s), $this->_files_pref())); } else { $this->remDirOpt($s); } } // Change permission if ( !empty($change_perm) ){ $this->changePermByReal($change_perm['old'], $change_perm['new'], $change_perm['type']); } return [ 'file_url' => $file_url, 'file_new_url' => $file_new_url, 'file_new' => $file_new, 'file_new_name' => $file_new_name, 'file_new_ext' => $ext ]; } $this->error("The old name and the new name are identical."); return false; } }

Renames a file or a directory. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.