I did it this way in my Angular app (tree-shakable calls / modular api):
import {
Storage, ref, getStorage, listAll, deleteObject, getBytes
} from '@angular/fire/storage';
...
async deleteDirectory(directoryPath: string) {
const storage = getStorage();
const listRef = ref(storage, directoryPath);
await this.deleteFiles(listRef);
}
async deleteFiles(listRef: any) {
await listAll(listRef)
.then((res) => {
res.prefixes.forEach((folderRef) => {
// if list item is a directory, recursively move through directory tree
this.deleteFiles(folderRef);
});
res.items.forEach((itemRef) => {
// if not a directory or empty, delete object
deleteObject(itemRef);
});
}).catch((error) => {
console.log('error deleting storage objects: ', error);
});
}