Delete non-empty Container (Inrupt libraries)

Hi everyone

how can i delete a container with file? When I try this with deleteContainer, return me an error caused by the fact that the Cannot be possible to delete a non-empty Container.
So, I need to delete all within a certain Container.
The idea will be that of trying to check if Container is empty (and continue to delete it), or delete all within.
I tried to use getContainedResourceUrlAll (from @inrupt/solid-client) on containerURL to get an array of URL to all the Resource/file within the container, and delete them, but not work. Seems that getContainedResourceUrlAll does not work with ContainerURL, because within its code it show the usage of getThing(), in relation with SolidDataset.
What do you think?

Unfortunately deleting all Resources in a Container in Solid isn’t straightforward, because the server can’t do it for you, and doing it in the client can result in all kinds of potential failures (e.g. the current user might not have deletion permissions for every Resource in there) leading to half-deleted child Resources.

So yes, you’ll need to manually delete everything in a Container (and deal with potential errors). getContainedResourceUrlAll takes the Container’s SolidDataset, not just its URL (i.e. you’ll have to call getSolidDataset(containerUrl) first). You can see the code Penny’s using to delete everything inside a Container here.

Copied here and cleaned up for your convenience:

export async function deleteRecursively(dataset) {
  const containedResourceUrls = getContainedResourceUrlAll(dataset);
  const containedDatasets = await Promise.all( resourceUrl => {
    try {
      return await getSolidDataset(resourceUrl, options);
    } catch(e) {
      // The Resource might not have been a SolidDataset;
      // we can delete it directly:
      await deleteFile(resourceUrl, options);
      return null;
  await Promise.all( containedDataset => {
    if (containedDataset === null) {
    return await deleteRecursively(containedDataset);
  return await deleteSolidDataset(dataset, options);

1 Like

You can also, use the SolidOS Webapp or Solid IDE which both provide a GUI view of your pod and can delete entire folder trees, including non-empty ones. The Solid-File-Client can be used as a library in any app and also has a method to recursively delete an entire folder tree.