deleteFile function

void deleteFile(
  1. FileSystemEntity file
)

Implementation

void deleteFile(FileSystemEntity file) {
  // This will throw a FileSystemException if the directory is missing permissions.
  try {
    if (!file.existsSync()) {
      return;
    }
  } on FileSystemException catch (err) {
    printError('Cannot clean ${file.path}.\n$err');
    return;
  }
  final Status deletionStatus = logger.startProgress(
      'Deleting ${file.basename}...',
      timeout: timeoutConfiguration.fastOperation);
  try {
    file.deleteSync(recursive: true);
  } on FileSystemException catch (error) {
    final String path = file.path;
    if (platform.isWindows) {
      printError('Failed to remove $path. '
          'A program may still be using a file in the directory or the directory itself. '
          'To find and stop such a program, see: '
          'https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used');
    } else {
      printError('Failed to remove $path: $error');
    }
  } finally {
    deletionStatus.stop();
  }
}