ring_22
ring_22

Reputation: 77

How can I download all files from Amazon S3 that are in a folder that was created last month?

How can I download a folder from Amazon S3 that was created last month until the present?

I have this code using boto:

for key in bucket.list():
   if last_month < dateutil.parser(key.last_modified).month:
      key.get_contents_to_filename(local_path + key.name)

The problem is the loop will take a long time because it's comparing each file in the folder. I only want to compare the folder timestamp.

If there's a way using the AWS CLI much better.

Upvotes: 1

Views: 880

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269470

This is not possible.

Amazon S3 does not use directories. It is a flat storage structure.

To give the appearance of directories, paths are prepended to the Key (filename) of an Object (file).

For example, an object called cat.jpg stored in a directory called animals would actually have a Key (filename) of animals/cat.jpg.

Since the directories do not exist, there is no way to retrieve properties from a directory.

(BTW, there is a concept of "common prefixes" that can work like directories when referring to multiple files, but it still isn't an actual directory.)

Upvotes: 1

Related Questions