John Constantine
John Constantine

Reputation: 421

listing files in Google Cloud Bucket

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.

Upvotes: 3

Views: 1172

Answers (1)

jterrace
jterrace

Reputation: 67063

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

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

Upvotes: 2

Related Questions