PDF文件移動

 網站鏈接:Java全棧工程師 | 以實例驅動學習 | how2j.cn

#!/usr/bin/env python
# coding: utf-8
# 讀取HTML文件夾中的.html文件
import os
# html的路徑
html_dir = 'C://2010html'
# pdf的路徑
pdf_dirs = 'C://2010'
# 已轉換完新建存儲的路徑
old_pdf = 'C://2010oldpdf'
files= os.listdir(html_dir) # 獲取HTML文件名稱
if not os.path.exists(old_pdf):
    os.makedirs(old_pdf)
    print("目錄創建成功!")
old_html = []  # 已轉換完的名稱列表
for file in files:
    if file.endswith('html'):
        old_html.append(file.replace(".html","")) # 添加進列表
# 遍歷PDF文件夾,移動文件
for file in os.listdir(pdf_dirs): 
    if file.replace(".pdf","") in old_html:
        old_path = os.path.join(pdf_dirs, file)
        new_path = os.path.join(old_pdf,file)
        os.rename(old_path,new_path)
        print("移動成功")

可安裝Anaconda3,然後搜索Spyder方可開始編寫Python

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章