copyDirectoryToAsync static method
目录拷贝
path 源目录路径
pathTarget 目标目录路径
showLog 是否展示消息日志
rootPath 根路径
Implementation
static Future<void> copyDirectoryToAsync(
String path,
String pathTarget, {
String? rootPath,
bool showLog = true,
}) async {
if (!await existsAsync(path) || !await isDirectoryAsync(path)) {
return;
}
if (showLog) {
final samePath = TextUtil.getSameTextInTwoStr(path, pathTarget);
Logger.info(
'copy dir',
'${path.replaceFirst(samePath, '')} -> ${pathTarget.replaceFirst(samePath, '')}',
);
}
Future<void> runCopy(
String rPath,
String rPathTarget, {
bool inShowLog = true,
}) async {
final diff = PathUtil.relative(rPath, from: path);
final mergedPathTarget = PathUtil.join(pathTarget, diff);
final fileList = await Directory(rPath).list().toList();
for (final f in fileList) {
if (await isDirectoryAsync(f.path)) {
await runCopy(
f.path,
pathTarget,
inShowLog: false,
);
} else if (await isFileAsync(f.path)) {
await copyFileToAsync(
f.path,
mergedPathTarget,
targetIsDirectory: true,
showLog: false,
);
}
}
}
await runCopy(path, pathTarget);
}