listing files in Google Cloud Bucket

Viewed 713

So to view all files in a GCP bucket we have a hook

 bucket = 'bucket-name'
 hook = GoogleCloudStorageHook(google_cloud_storage_conn_id='ListenerScience',
                                  delegate_to=None)
list_of_files = hook.list(bucket)

But if I wanted to view files inside a folder in the bucket like

'bucket-name/FolderOne/SubFolder'

I get an error saying not a directory. Is there a simple way to view all the files inside folders of bucket.

1 Answers

You want to set the prefix option to the list method, e.g. something like:

list_of_files = hook.list(bucket, prefix='FolderOne/SubFolder')
Related