copyDirectory static method
Implementation
static void copyDirectory(Directory source, Directory destination) {
if (!source.existsSync()) {
throw Exception("Source directory doesn't exist: ${source.path}");
}
if (destination.existsSync()) {
destination.deleteSync(recursive: true);
}
destination.createSync(recursive: true);
source.listSync(recursive: false).forEach((FileSystemEntity entity) {
if (entity is File) {
entity.copySync('${destination.path}/${entity.uri.pathSegments.last}');
} else if (entity is Directory) {
copyDirectory(entity, Directory('${destination.path}/${entity.uri.pathSegments.last}'));
}
});
}