delete method

Future<bool> delete(
  1. String filePath, {
  2. dynamic sudo = false,
  3. dynamic recursive = false,
  4. dynamic force = false,
})

Delete filePath If sudo is true, the file will be deleted with sudo permissions If recursive is true, the file will be deleted recursively If force is true, the file will be deleted even if it is read-only

Implementation

Future<bool> delete(String filePath, {sudo = false, recursive = false, force = false}) async {
  final file = File(filePath);

  if (!file.existsSync()) {
    return true;
  }
  try {
    if (Platform.isWindows) {
      await file.delete();
      return true;
    } else {
      List<String> args = ['-f', filePath];
      if (recursive) {
        args.insert(0, '-r');
      }
      if (force) {
        args.insert(0, '-f');
      }
      final result = await simple('rm', args, sudo: sudo);
      return result.exitCode == 0;
    }
  } catch (e) {
    return false;
  }
}