northtree
northtree

Reputation: 9285

How to grab the first and last file of given Google Cloud Storage folder?

I want to get the first and last file (based on Last modified timestamp) from one folder gs://bundle_name/folder_name/, which contains large number of files. It seems not supported by gsutil or Cloud API.

Upvotes: 1

Views: 1785

Answers (2)

mhouglum
mhouglum

Reputation: 2593

+1 to the other answer here. This isn't supported natively by the service, but you could use the client library (or gsutil if you want to do some quick-n-dirty regex parsing instead) to list all the files under the desired prefix, then iterate over them and keep track of the newest and oldest entries (or whatever filtering criteria you wanted to apply). This question is pretty close to a duplicate of this gsutil GitHub issue, where I provided an example Bash script to do something similar.

Upvotes: 1

Doug Stevenson
Doug Stevenson

Reputation: 317828

You're asking for an expensive operation for a product that just wants to store your files. It's not a database, and it's meant to be massively scalable, so you won't see this operation supported natively. Consider instead using a database to record the times of all the files, and query the database to find the relevant file instead of the storage system.

Upvotes: 5

Related Questions