简体   繁体   中英

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.

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM