Google-cloud-python: Cloud Storage: list_blobs(delimiter='/', prefix="subdir/") includes subdir?

Created on 6 Apr 2018  路  4Comments  路  Source: googleapis/google-cloud-python

  1. Specify the API at the beginning of the title: Cloud Storage
  2. Python3, Container Optimized OS in GCE
  3. Python 3.5.3
  4. Library version: google-cloud-storage (1.8.0)

Code example (7):

for blob in bucket.list_blobs(delimiter='/', prefix='subdir/'):
    if blob.name = 'subdir/':
        print("should not happen")
    else: 
        # real blob, proceed

Maybe I am not getting it, but after looking into the API and the issues I thought that above should not happen should not be printed when using delimiter and prefix. Is this the intended behavior, so that I must filter out the subdir itself in the loop to only operate on real blobs?

question storage

Most helpful comment

HI @james-woods,

Looking for clarification. I'm assuming you're seeing "should not happen" as it found a blob with subdir/?

If this is correct, it's possible that you created a "folder" using the Cloud Storage browser. When a folder is created an empty object with the folder name is created to "simulate" a file structure even though a file structure doesn't really exist.

All 4 comments

@frankyn FYI

HI @james-woods,

Looking for clarification. I'm assuming you're seeing "should not happen" as it found a blob with subdir/?

If this is correct, it's possible that you created a "folder" using the Cloud Storage browser. When a folder is created an empty object with the folder name is created to "simulate" a file structure even though a file structure doesn't really exist.

Hi @frankyn - yes. I think you've nailed it. My question would be how I can remove the artificial folder with the minimum amount of steps as the "folder" keeps holds over 90k objects.

gsutil rm gs://bucket/subdir/ did the trick :)

Was this page helpful?
0 / 5 - 0 ratings