|
发表于 2020-12-24 10:42:24
|
显示全部楼层
- import os,time,shutil
- imgpaths = []
- filepath = 'C:\\Users\\Administrator\\Desktop\\'
- def getformat(imgpath): #返回文件后缀
- return os.path.splitext(imgpath)[-1]
- def isimg(path): #判断是否为图片
- imgformats = ['.png', '.jpg', '.jpeg', '.PNG', '.JPG', '.JPEG']
- if getformat(path) in imgformats:
- return True
- else:
- return False
-
- def getpaths(path):#获取图片路径
- for file in os.listdir(path):
- filepath = os.path.join(path, file)
- if isimg(filepath):
- imgpaths.append(filepath)
- def gettime(file):#获取图片创建时间
- time1 = os.path.getctime(file)
- time2 = time.localtime(time1)
- filetime = time.strftime('%Y-%m\\',time2)
- return filetime
- def newimgpath(oldpath):#创建新文件路径
- newpath = input('New:')
- newpath = newpath + gettime(file)
- try:
- os.mkdir(newpath)
- except:
- pass
复制代码
剩下的自己补充吧,写不动了 |
|