copy method
Copy oldPath to newPath
If sudo is true, the file will be copied with sudo permissions
If recursive is true, the file will be copied recursively
If force is true, the file will be copied even if it already exists
If preserve is true, the file will be copied preserving the original
permissions
Implementation
Future<bool> copy(
String oldPath,
String newPath, {
sudo = false,
recursive = false,
force = false,
preserve = false,
}) async {
try {
if (Platform.isWindows) {
await File(oldPath).copy(newPath);
return true;
} else {
List<String> args = [oldPath, newPath];
if (recursive) {
args.insert(0, '-r');
}
if (force) {
args.insert(0, '-f');
}
if (preserve) {
args.insert(0, '-p');
}
final result = await simple('cp', args, sudo: sudo);
return result.exitCode == 0;
}
} catch (e) {
return false;
}
}