copy method

Future<void> copy(
  1. Directory source,
  2. Directory destination, {
  3. ShouldCopy? shouldCopy,
  4. PostCopy? postCopy,
})

Implementation

Future<void> copy(Directory source, Directory destination,
    {ShouldCopy? shouldCopy, PostCopy? postCopy}) async {
  await visit(source, (entity, depth) async {
    final relativePath = relative(entity.path, from: source.path);
    final shouldCopyEntity = shouldCopy?.call(entity, depth) ?? true;
    if (!shouldCopyEntity) {
      return false;
    }
    if (entity is Directory) {
      var newDirectory =
          Directory(join(destination.absolute.path, relativePath));
      await newDirectory.create();
      await postCopy?.call(newDirectory, depth);
    } else if (entity is File) {
      final copied = await entity.copy(join(destination.path, relativePath));
      await postCopy?.call(copied, depth);
    }
    return true;
  });
}