变更pdf名字

#!/usr/bin/env python
# encoding: utf-8
import os


def rename(dirname, old, new):
    olddir = os.path.join(dirname, old)
    newdir = os.path.join(dirname, new)
    os.rename(olddir, newdir)


path = 'D://Users/Desktop/中国证券监督管理委员会/x6'
for filename in os.listdir(path):
    print(filename)
    new = filename.replace('.docx', '').replace('doc','').replace('.pdf','') + '.pdf'
    rename(path, filename, new)

你可能感兴趣的:(变更pdf名字)