kaysush
kaysush

Reputation: 4836

Correct way to use Google Cloud Storage SDK

I am trying to list of files in my GCP bucket using Google Cloud Storage SDK using scala.

For example I have a bucket named bucket-1 and there is a folder inside it folder-1 and I want to list all the files inside folder-1.

I tried using below code but it doesn't return anything inside folder-1

val files = storage.list("bucket-1",BlobListOption.currentDirectory(), BlobListOption.prefix("folder-1"))

The problem is objects/files inside the folder-1 doesn't have any set prefix due to which I can't add it in BlobListOption.prefix call.

Upvotes: 0

Views: 313

Answers (1)

John Hanley
John Hanley

Reputation: 81356

To list all the files in the directory folder-1 your prefix should be folder-1/and you should specify a delimiter of /.

objects will be in the returned items array. Directories (which do not exists and are emulated) are returned in the prefixes array.

Upvotes: 1

Related Questions