遍历文件夹下的文件,进行文件复制与重命名

2019-04-15  本文已影响0人  求索_700e

#!/usr/bin/python

# -*- coding: utf-8 -*-

import os,shutil

subfix="RED.bmp"

dstfile_prefix='./RED/'

cnt_start=178

def process_files(path):

    cnt=cnt_start

    for root , dirs, files in os.walk(path):

        for name in files:

            if name.endswith(subfix):

                cnt+=1

                srcfile=os.path.join(root, name)

                print(cnt,name)

                dstfile=dstfile_prefix+str(cnt)+".bmp"

                shutil.copyfile(srcfile,dstfile)     

if __name__ == "__main__":

    path = './body'

    process_files(path)

上一篇 下一篇

猜你喜欢

热点阅读