moveTree function

void moveTree(
  1. String from,
  2. String to,
  3. {bool overwrite = false,
  4. bool includeHidden = false,
  5. bool filter(
    1. String file
    ) = _allowAll}
)

Recursively moves the contents of the from directory to the to the to path with an optional filter.

When filtering any files that don't match the filter will be left in the from directory tree.

Any from directories that are emptied as a result of the move will be removed. This includes the from directory itself.

from must be a directory

to must be a directory and its parent directory must exist.

If any moved files already exists in the to path then an exeption is throw and a parital move may occured.

You can force moveTree to overwrite files in the to directory by setting overwrite to true (defaults to false).

moveTree("/tmp/", "/tmp/new_dir", overwrite: true);

By default hidden files are ignored. To allow hidden files to be passed set includeHidden to true.

You can select which files/directories are to be moved by passing a filter.

If the filter returns true then the file/directory will be copied.

If a filter isn't passed then all files/directories are copied as per the includeHidden state.

moveTree("/tmp/", "/tmp/new_dir", overwrite: true
   // allow only files ending in dart to be copied.
  , filter: (file) => extension(file) == 'dart');

The filter method can also be used to report progress as it is called just before we move a file or directory.

moveTree("/tmp/", "/tmp/new_dir", overwrite: true
  , filter: (entity) {
  var include = extension(entity) == 'dart';
  if (include) {
    print('moving: $file');
  }
  return include;
});

The default for overwrite is false.

If an error occurs a MoveTreeException is thrown.

EXPERIMENTAL

Implementation

void moveTree(
  String from,
  String to, {
  bool overwrite = false,
  bool includeHidden = false,
  bool Function(String file) filter = _allowAll,
}) =>
    waitForEx(
      // ignore: discarded_futures
      core.moveTree(
        from,
        to,
        overwrite: overwrite,
        includeHidden: includeHidden,
        filter: filter,
      ),
    );