Description
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)])