PYTHON得到pdf页数、遍历当前文件夹
生活随笔
收集整理的這篇文章主要介紹了
PYTHON得到pdf页数、遍历当前文件夹
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#第一步安裝PyPDF2
pip install PyPDF2#第二步導入相應的模塊
from PyPDF2 import PdfFileReader#第三步:定義相對應的函數
def get_num_pages(file_path):"""獲取文件總頁碼:param file_path: 文件路徑:return:"""reader = PdfFileReader(file_path)# 不解密可能會報錯:PyPDF2.utils.PdfReadError: File has not been decryptedif reader.isEncrypted:reader.decrypt('')page_num = reader.getNumPages()return page_num
2#遍歷文件名
def get_files():for filepath,dirnames,filenames in os.walk(r'E:\test2'):for filename in filenames:print(os.path.join(filepath,filename))
3 列出當前文件夾所有文件
總結
以上是生活随笔為你收集整理的PYTHON得到pdf页数、遍历当前文件夹的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从贪心选择到探索决策:基于强化学习的多样
- 下一篇: websocket python爬虫_p