2

I have a gcs file hierarchy that has a few directory under my bucket and each directory has tons of files. I want to query on my bucket and return all the directories.

I am currently outside appengine so I am using google-api-services-storage sdk, however it seems that the list query is returning every leaf files instead. As I said in the beginning as the number of my directory is fairly small but number of files in each directory is huge, I really hope I won't need to touch what is within each directory when I do the listing.

(By saying that, I know that there is actually no "directory" in gcs, just simply file object with different naming hierarchy but in appengine it is allowing gcs client to set whether to do the listing recursively or not, and the query performs really fast. I am wondering whether there might anything similar outside appengine

I searched on the document however it seems to have no relevant parameters that I could config the query?

Xinwei Liu
  • 333
  • 6
  • 15

1 Answers1

3

The AE gcs client is using the delimiter and prefix options (from the document you mentioned, though it uses the XML API) for simulating a non-recursive folder listing.

You can achieve that by setting the prefix to the path of the "folder" to list and setting the delimiter to '/' (or whatever is your path delimiter).

Also, I recommend looking at gcloud-java-storage for an easier to use API that is not specific to AE.

ozarov
  • 1,051
  • 6
  • 7