move method

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

Rename or move oldPath to newPath If sudo is true, the file will be moved with sudo permissions

Implementation

Future<bool> move(
  String $oldPath,
  String $newPath, {
  sudo = false,
  force = false,
  recursive = false,
  preserve = false,
}) async {
  try {
    if (Platform.isWindows) {
      await File($oldPath).rename($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('mv', args, sudo: sudo);
      return result.exitCode == 0;
    }
  } catch (e) {
    return false;
  }
}