Python: 遍历给定目录下的pdf文档并进行重命名

文章目录

    • 编程目的
    • 参考
    • 代码(一)
    • 代码(二)

编程目的

因需要大量重命名pdf文档为[0…n].pdf,就搜集了资料写了代码,并解决自己的问题。

参考

感谢各位分享的资源。

python3.3 遍历文件夹及文件 小例
python文件重命名
一文看懂Python对文件和文件夹的操作: 含os, shutil和glob模块详解

代码(一)

import glob
import os.path

# 找到给定的root_dir下的pdf文档并重命名为 0.pdf ... n.pdf
# root directory the location you want to find pdf files
# user defined root_dir
# change root_dir according to your needs
root_dir = r'C:\Users\ECHO\Documents\test'

# find all the pdf file in the root_dir
pdfFiles = glob.glob(os.path.join(root_dir, '*.pdf'))

# renamed the 

你可能感兴趣的:(python,coding,python)