Skip to content

Unexpected behavior when retrieving subfolders based on prefixes #1495

Open
@uatach

Description

@uatach

Both https://cloud.google.com/storage/docs/listing-objects and https://cloud.google.com/storage/docs/samples/storage-list-files-with-prefix show examples of listing "folders" in the case where the bucket has this structure:

a/1.txt
a/b/2.txt

but this does not look like an usual structure for a bucket, a more common structure would be something like this:

a/b/1.txt
a/b/2.txt
a/c/1.txt

then, we would like to retrieve a list of "subfolders" similar to:

a/b
a/c

but that does not work, the client returns an empty set in blobs.prefixes, I've also tried adding include_folders_as_prefixes and include_trailing_delimiter as True without success...

How can we retrieve the list of subfolders in a case like this?

As a workaround, I'm currently using something like this:

set(['/'.join(x.name.split('/')[:-1]) for x in Client().list_blobs(bucket_name, prefix=prefix)])

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions