使用python读取文件夹中的许多图像

时间:2016-01-08 09:56:16

标签: python image python-2.7

我第一次使用python:我有一个包含数百个图像的文件夹,我需要读取每个图像的时间。 我知道如何读取图像的时间,但我不知道如何按顺序打开此文件夹中的每个图像。 谢谢你的帮助

1 个答案:

答案 0 :(得分:2)

如果要按字母顺序打印它们,可以使用以下代码。使用if file.endswith(".png"),您只能获得.png个文件。如果您在同一目录中有任何其他类型的文件,这是很好的。

import os, os.path, time
for file in os.listdir("/folder_name"):
    if file.endswith(".png"):
        print str(file) + " - Creation date: " + str(time.ctime(os.path.getctime(file)))

输出:

IMG_01.png - Creation date: Thu Nov 12 09:33:13 2015
相关问题