0
votes

I have a storage bucket in google cloud. I have a few directories which I created with files in them.

I know that if I want to cycle through all the files in all the directories, I can use the following command:

for file in list(source_bucket.list_blobs()):
    file_path=f"gs://{file.bucket.name}/{file.name}"
    print(file_path)

Is there a way to only cycle through one of the directories?

1

1 Answers

1
votes

I suggest studying the Cloud Storage list API in more detail. It looks like you have only experimented with the most basic use of list_blobs(). As you can see from the linked API documentation, you can pass a prefix parameter to limit the scope of the list to some path. source_bucket.list_blobs(prefix="path"):