Python 獲取指定資料夾下所有的.docx檔案
阿新 • • 發佈:2021-01-22
話不多說 , 直接上程式碼
# 定義指定路徑 , 或者自己輸入
path = r'E:\root'
# path = input("請輸入路徑:")
# 定義接收元組
vv= []
def read(path):
for i in os.listdir(path):
fi_d = os.path.join(path, i)
if os.path.isdir(fi_d):
# 呼叫遞迴
read(fi_d)
else:
if os.path.splitext(i)[1]=='.docx':
vv.append(os.path.join(fi_d))
read(path)
# 列印所有docx的絕對路徑
print(vv)