s3- boto-按上传时间列出存储桶中的文件 [英] s3- boto- list files within a bucket by upload time
本文介绍了s3- boto-按上传时间列出存储桶中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要每小时从s3服务器下载100个最新文件.
I need to download every hour 100 newest files from s3 server.
bucketList = bucket.list(PREFIX)
上面的代码创建文件列表,但是它不取决于文件的上传时间,因为它按文件名列出?
The code above creates list of the files but it is not depend on the uploading time of the files, since it lists by file name?
我无法使用文件名.它是随机给的.
I can do nothing with file name. It is given randomly.
谢谢.
推荐答案
列表多大?您可以在Key的"last_modified"属性上对列表进行排序
How big is the list? You could sort the list on the 'last_modified' attr of the Key
orderedList = sorted(bucketList, key=lambda k: k.last_modified)
keysYouWant = orderedList[0:100]
如果您的列表很大,这可能无效.在boto.s3.bucket.Bucket中查看内联文档以获取list()函数.
If your list is HUGE this may not be efficient. Check out the inline docs for the list() function in boto.s3.bucket.Bucket.
这篇关于s3- boto-按上传时间列出存储桶中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文