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
897 stars 369 forks source link

How to delete an empty folder? #2520

Open jezaman opened 1 week ago

jezaman commented 1 week 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 4 days 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 4 days 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 4 days 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.