0
votes

I am using the Google Cloud Storage Python API to gather the list of files contained in specific subdirectories within Cloud Storage.

bucket.list_blobs(prefix='abc')

However, the issue with this is that I only want to gather the list of files within:

bucket/abc/

However, what's being called is:

bucket/abc/ AND bucket/abc-123/

How do I ensure that the prefix is to be used as an exact match? Thanks.

1
Do you want only blobs that are directly under bucket/abc? And nothing from the sub directories? - AnkurSaxena
I want all blobs within all sub-directories within bucket/abc. E.g. bucket/abc/1/, bucket/abc/2/, bucket/abc/3/, bucket/abc/test.txt should all have their blobs listed. - Mullins

1 Answers

3
votes

Adding a / to the end of your prefix should prevent matching with other files/directories starting with same prefix as your target directory.

bucket.list_blobs(prefix='abc/')