首先创建具有特定扩展名的子目录列出文件,我是新来的特别节目和Python,因此我努力寻找一个合适的解决方案。的Python:在过去24小时内
我试图寻找与递归特定扩展名已创建仅在过去24小时内,要么将结果打印到屏幕上,保存到文件中,这些文件复制到目录中的文件。
下面是一个例子做了大部分的我想实现什么,除非它找到与给定的扩展名的文件的代码,但是,我只需要在过去24小时或更短时间内创建的文件。
import os
import shutil
topdir = r"C:\Docs"
dstdir = r"C:\test"
exten = ".png"
for dname, names, files in os.walk(topdir):
for name in files:
if name.lower().endswith(exten):
# Prints result of walk
print(os.path.join(dname, name))
#copy all files with given extension to the dst folder
path = os.path.realpath(os.path.join(dname, name))
shutil.copy2(path, dstdir)
【如何获得文件的创建和修改日期/ Python中的时间?(http://stackoverflow.com/q/237079/953482) – Kevin
就像@Kevin所说的,使用'time.ctime'和'os.path.getctime'。 –