copyDirectory function
Copy the directory at path recursively into target.
Returns null if path does not lead to a Directory,
else the newly created Directory gets returned.
Implementation
Future<Directory?> copyDirectory(String path, Directory target) async {
// See [copyDirectorySync] for the synchronous version.
// ignore: avoid_slow_async_io
if (!await FileSystemEntity.isDirectory(path)) return null;
final source = Directory(path).absolute;
final actualTargetDir = target.directory(source.name).absolute;
await source.copyRecursively(actualTargetDir);
return actualTargetDir;
}