我查找代码以使用python 2.7打开最新的文件夹。
之后我得到x picures:
PATH = "/path/to/your/folder"
DST = "/destination/folder"
pictures = [os.path.join(PATH, pic) for pic in os.listdir(PATH)]
pictures.sort(key=os.path.getmtime)
return (pictures[-7:])
我可以复制的内容:
def kopieren():
for pic in get_last_pics():
print(datetime.fromtimestamp(os.path.getmtime(pic)))
shutil.copy2(os.path.join(pic), os.path.join(DST))
kopieren()
任何人都可以给我一些想法,我怎样才能跳进最新的文件夹来获取图片。
答案 0 :(得分:0)
以下程序允许您获取最后修改过的文件夹的路径:
import os, sys
def get_newest_folder(path):
newest = None
date = None
for f in get_all_folders(path):
if (date == None or date < os.path.getmtime(f)):
newest = f
date = os.path.getmtime(f)
return os.path.join(path, newest)
def get_all_folders(path):
return [x for x in os.listdir(path) if os.path.isfile(x) == False]
if __name__ == "__main__":
print(get_newest_folder(sys.argv[1]))
答案 1 :(得分:0)