copyDirectory function
Implementation
void copyDirectory(Directory source, Directory destination) {
// 获取源文件夹中的所有内容
source.listSync().forEach((entity) {
if (entity is File) {
// 如果是文件,则复制到目标文件夹中
final newPath = join(destination.path, basename(entity.path));
entity.copySync(newPath);
} else if (entity is Directory) {
// 如果是文件夹,则递归复制子文件夹
final newDirectory =
Directory(join(destination.path, basename(entity.path)));
newDirectory.createSync();
copyDirectory(entity, newDirectory);
}
});
}