How to find which all folders in gcp bucket contain a file with particular name using java api

Viewed 329

I have a Google cloud storage bucket with following structure Gs://myBucket/folder1/1.txt Gs://myBucket/folder2/1.txt Gs://myBucket/folder3/3.txt

I wish to know using Java api which all folders contain file with name 1.txt. in my above example it will be folder1 and folder2

1 Answers

Folders aren't a resource in Google Cloud Storage (GCS), see Folders.

The only resource that Buckets may contain are Objects.

There isn't a Folder resource in GCS Buckets that you can grab a handle to and which contains File things.

Object names permit "/" and many tools manifest this as if it were a directory path separator (but it really isn't).

You will need to iterate over every object (see: List and pattern-match on every Object name ending e.g. 1.txt.

Related