moveToBin function

Future<File?> moveToBin(
  1. File file, {
  2. Run? runner,
  3. Directory? binDir,
  4. bool sudo = true,
})

Moves a file to the system's bin folder. If binDir is not specified, the system's bin folder will be used. If runner is not specified, a new Run instance will be used. If sudo is true, the file will be moved using sudo.

Implementation

Future<File?> moveToBin(File file, {Run? runner, Directory? binDir, bool sudo = true}) async {
  binDir ??= binDirectory();
  runner ??= Run();

  try {
    final dest = File(join(binDir.absolute.path, basename(file.absolute.path)));
    final success = await runner.move(file.absolute.path, dest.absolute.path, sudo: sudo);
    if (success) {
      return dest.absolute;
    }
  } catch (e) {
    return null;
  }

  return null;
}