copyDir function

void copyDir(
  1. Directory src,
  2. Directory dst
)

Recursively copies the contents of src directory to dst directory.

Implementation

void copyDir(Directory src, Directory dst) {
  if (!dst.existsSync()) {
    dst.createSync(recursive: true);
  }

  for (final entity in src.listSync()) {
    if (entity is File) {
      entity.copySync('${dst.path}/${entity.uri.pathSegments.last}');
    } else if (entity is Directory) {
      copyDir(entity, Directory('${dst.path}/${entity.uri.pathSegments.last}'));
    }
  }
}