python 从文件夹中提取特定图片至另一文件夹下

2022-08-03,,,,

# -*- coding:utf8 -*-

import os
import shutil

class BatchRename():
    '''
    批量重命名文件夹中的图片文件
    '''
    def __init__(self):
        self.path = 'E:/check/ff'
        self.newpath = 'E:/check/ff1'

    def tiqu(self):
        filelist = os.listdir(self.path)
        # print(filelist)
        # total_num = len(filelist)
        for file in filelist:
            # print file
            filedir = os.path.join(self.path, file)
            # print filedir
            (shotname, extension) = os.path.splitext(file)
#            a = os.path.splitext(file)
            b = shotname.split('-')[1]
            # print(shotname)

            if (int(b) % 15 == 1):
                print (shotname)
                # print(str(filedir))
                shutil.copy(str(filedir), os.path.join(self.newpath, b+'.jpeg'))

if __name__ == '__main__':
    demo = BatchRename()
    demo.tiqu()

本文地址:https://blog.csdn.net/mndlgzzd/article/details/107356799

《python 从文件夹中提取特定图片至另一文件夹下.doc》

下载本文的Word格式文档,以方便收藏与打印。