lib/file/rename.js
function rename(source, destination) {
  const parent = path.dirname(destination);
  if (exists(destination)) {
    if (isDirectory(destination)) {
      destination = path.join(destination, path.basename(source));
    } else {
      if (isDirectory(source)) {
        throw new Error(`Cannot rename directory ${source} into existing file ${destination}`);
      }
    }
  } else if (!exists(parent)) {
    mkdir(parent);
  }
  try {
    fs.renameSync(source, destination);
  } catch (e) {
    if (e.code !== 'EXDEV') throw e;
    // Fallback for moving across devices
    copy(source, destination);
    fileDelete(source);
  }
}
function rename(source, destination) {
  const parent = path.dirname(destination);
  if (exists(destination)) {
    if (isDirectory(destination)) {
      destination = path.join(destination, path.basename(source));
    } else {
      if (isDirectory(source)) {
        throw new Error(`Cannot rename directory ${source} into existing file ${destination}`);
      }
    }
  } else if (!exists(parent)) {
    mkdir(parent);
  }
  try {
    fs.renameSync(source, destination);
  } catch (e) {
    if (e.code !== 'EXDEV') throw e;
    // Fallback for moving across devices
    copy(source, destination);
    fileDelete(source);
  }
}
function rename ( source , destination ) { const parent = path . dirname ( destination ) ; if ( exists ( destination ) ) { if ( isDirectory ( destination ) ) { destination = path . join ( destination , path . basename ( source ) ) ; } else { if ( isDirectory ( source ) ) { throw new Error ( ` ${ source } ${ destination } ` ) ; } } } else if ( ! exists ( parent ) ) { mkdir ( parent ) ; } try { fs . renameSync ( source , destination ) ; } catch ( e ) { if ( e . code !== 'EXDEV' ) throw e ; // Fallback for moving across devices copy ( source , destination ) ; fileDelete ( source ) ; } }
Rename file or directory
@function $file~rename
@param {string} source
@param {string} destination
@example
// Rename default configuration file
$file.move('conf/php.ini-production', 'conf/php.ini');
 
Alias of {@link $file~rename}
@function $file~move
Rename file or directory