copyFolder function

Future<void> copyFolder(
  1. String sourcePath,
  2. String destinationPath
)

Implementation

Future<void> copyFolder(String sourcePath, String destinationPath) async {
  Directory sourceDir = Directory(sourcePath);
  Directory destDir = Directory(destinationPath);
  if (!await destDir.exists()) {
    await destDir.create(recursive: true);
  }
  List<FileSystemEntity> contents = sourceDir.listSync();
  for (var entity in contents) {
    String newPath = path.join(destinationPath, path.basename(entity.path));
    if (entity is Directory) {
      await copyFolder(entity.path, newPath);
    } else if (entity is File) {
      await entity.copy(newPath);
    }
  }
}