googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
903 stars 370 forks source link

How to delete an empty folder? #2520

Closed jezaman closed 1 month ago

jezaman commented 2 months ago

Hello,

I have a setup where inside my bucket, i organise files based on project So files are stored as {projectUUID}/{filename}

How do i delete the actual empty folder? I found that i can use deleteFiles to delete the files inside the folder await bucket.deleteFiles({ prefix: ${project}/, });

But this doesn't delete the folder. I tried doing a manual delete of the folder path afterwards but that doesn't seem to work. I tried removing the trailing '/' but that didn't have an effect either.

I really think this repo could use some basic examples. There is so many super complex examples already there, but there is not a basic example of "Delete multiple files" or a "Delete a folder".

And yes i know technically there are no folders inside the bucket.

ddelgrosso1 commented 2 months ago

Hello @jezaman, it sounds like you are referring to simulated folders. If so, there is nothing in particular you need to do to delete the folder because it doesn't actually exist. See the docs here

jezaman commented 2 months ago

Yes i know that, but the empty non-existent folder does remain in my Google Cloud Storage overview in Google Cloud Console. I was expecting that if all the files would be removed, the path would also be removed from the Console.

ddelgrosso1 commented 2 months ago

@jezaman I would try performing a getFiles() to see if the folder / files still exist. It might be some weirdness with the console. I can also check if having a softDeletePolicy has any impact.

ddelgrosso1 commented 1 month ago

Closing as I don't think there is anything else to be done. Please feel free to reopen if a question still remains.