move function

void move(
  1. String from,
  2. String to, {
  3. bool overwrite = false,
})

Moves the file from to the location to.

createDir('/tmp/folder');
move('/tmp/fred.txt', '/tmp/folder/tom.txt');

from must be a file.

to may be a file or a path.

If to is a file then a rename occurs.

if to is a path then from is moved to the given path.

If the move fails for any reason a MoveException is thrown.

@Throwing(ArgumentError)

Implementation

void move(String from, String to, {bool overwrite = false}) {
  verbose(
      () => 'move ${truepath(from)} -> ${truepath(to)} overwrite: $overwrite');

  var dest = to;

  if (isDirectory(to)) {
    dest = p.join(to, p.basename(from));
  }

  if (!overwrite && exists(dest)) {
    throw MoveException(
      'The [to] path ${truepath(dest)} already exists.'
      ' Use overwrite:true ',
    );
  }
  try {
    File(from).renameSync(dest);
  } on FileSystemException catch (_) {
    /// Invalid cross-device link
    /// We can't move files across a partition so
    /// do a copy/delete.
    copy(from, to, overwrite: overwrite);
    delete(from);
  } catch (e) {
    _improveError(e, from, to);
  }
}