copyTo method
void
copyTo(})
Recursively copies a directory + subdirectories into a target directory. Similar to Copy-Item in PowerShell.
Implementation
void copyTo(
final Directory destination, {
final List<String> ignoreDirList = const [],
final List<String> ignoreFileList = const [],
}) {
if (destination.existsSync() == false) {
destination.createSync(
recursive: true,
);
}
listSync().forEach((final entity) {
List<String> slebews = path.split(entity.path);
if (slebews.contains(".git")) {
return;
}
if (slebews.contains(".dart_tool")) {
return;
}
if (entity is Directory) {
if (ignoreDirList.contains(path.basename(entity.path))) {
return;
}
final newDirectory = Directory(
path.join(destination.absolute.path, path.basename(entity.path)),
)..createSync();
entity.absolute.copyTo(newDirectory);
} else if (entity is File) {
if (ignoreFileList.contains(path.basename(entity.path))) {
return;
}
entity.copySync(
path.join(destination.path, path.basename(entity.path)),
);
}
});
}