copy method

Future<bool> copy(
  1. String oldPath,
  2. String newPath, {
  3. dynamic sudo = false,
  4. dynamic recursive = false,
  5. dynamic force = false,
  6. dynamic preserve = false,
})

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;
  }
}