Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete an empty folder? #2520

Open
jezaman opened this issue Sep 16, 2024 · 4 comments
Open

How to delete an empty folder? #2520

jezaman opened this issue Sep 16, 2024 · 4 comments
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@jezaman
Copy link

jezaman commented Sep 16, 2024

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.

@jezaman jezaman added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Sep 16, 2024
@jezaman jezaman changed the title How to delete an empty folder>? How to delete an empty folder? Sep 16, 2024
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Sep 16, 2024
@ddelgrosso1
Copy link
Contributor

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

@ddelgrosso1 ddelgrosso1 self-assigned this Sep 23, 2024
@jezaman
Copy link
Author

jezaman commented Sep 24, 2024

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
Copy link
Contributor

@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.

@vuduong97
Copy link

Hello @jezaman , i encountering an issue with the deleteFolder method from the @google-cloud/storage-control library, with Hierarchical namespace enabled. When I try to delete a folder, I encounter the error: "The folder you tried to delete is not empty." Below is the code snippet I am using:

async deleteFolder() {
    const res = await this.controlClient.deleteFolder({
      name: `projects/_/buckets/${this.bucketName}/folders/Content/test/`,
    });
    return "Delete folder successfully";
}

image

Could you please provide some guidance on whether this method is designed exclusively for empty folders, or if there is a recommended approach for handling non-empty folders? Any assistance would be greatly appreciated.
Thank you for your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants