deleteFolder method

void deleteFolder(
  1. String path
)

Delete the folder with the given path and recursively delete nested files and folders.

Implementation

void deleteFolder(String path) {
  var data = _pathToData[path];
  if (data is! _FolderData) {
    throw FileSystemException(path, 'Not a folder.');
  }

  for (var childName in data.childNames.toList()) {
    var childPath = pathContext.join(path, childName);
    var child = getResource(childPath);
    if (child is File) {
      deleteFile(child.path);
    } else if (child is Folder) {
      deleteFolder(child.path);
    } else {
      throw 'failed to delete resource: $child';
    }
  }

  if (_pathToData[path] != data) {
    throw StateError('Unexpected concurrent modification: $path');
  }
  if (data.childNames.isNotEmpty) {
    throw StateError('Must be empty.');
  }

  _pathToData.remove(path);
  _removeFromParentFolderData(path);

  _notifyWatchers(path, ChangeType.REMOVE);
}