文件夹中含有子文件夹,修改子文件夹中的图像存储格式,把png图像改为jpg图像,python代码如下: import os import cv2 filePath = 'C:\\Users\\admin\\Desktop\\img' for dirpath, dirnames, filenames in os.walk(filePath): path = [os.path.join(dirpath, names) for names in filenames] for str in path:
# coding:utf-8 import os, re for i in os.walk('d:'+os.sep): for txt in i[2]: try: txt = re.match(r'(.*)(\.txt)', txt).group(0) print os.path.join(i[0], txt) except: pass