copyTree function

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

Implementation

void copyTree(
  String from,
  String to, {
  bool overwrite = false,
  bool Function(String file) filter = _allowAll,
  bool includeHidden = false,
  bool recursive = true,
}) {
  if (!isDirectory(from)) {
    StatusHelper.failed(
        'The [from] path ${truepath(from)} must be a directory.');
  }
  if (!exists(to)) {
    StatusHelper.failed('The [to] path ${truepath(to)} must already exist.');
  }

  if (!isDirectory(to)) {
    StatusHelper.failed('The [to] path ${truepath(to)} must be a directory.');
  }

  try {
    final items = find(
      '*',
      workingDirectory: from,
      includeHidden: includeHidden,
      recursive: recursive,
    );

    items.forEach((item) {
      _process(
        item,
        filter,
        from,
        to,
        overwrite: overwrite,
        recursive: recursive,
      );
    });
  }
  // ignore: avoid_catches_without_on_clauses
  catch (e) {
    StatusHelper.failed(
        'An error occured copying directory  ${truepath(from)} to ${truepath(to)}. Error: $e');
  }
}