【轉】Python查找某文件夾下的所有excel文件


 

# -*- coding: utf-8 -*-
# author:baoshan

import os

dirname = r'D:\0.shenma\01.聊城資料\01.數據資料\02.聊城年鑒數據\2017年鑒'
filename = ".xls"

result = []
def search(dirname=dirname, filename=""):
    for item in os.listdir(dirname):
        item_path = os.path.join(dirname, item)
        if os.path.isdir(item_path):
            search(item_path, filename)
        elif os.path.isfile(item_path):
            if filename in item:
                global result
                result.append(item_path +";")
                print(item_path+";")


if __name__ == '__main__':
    search(dirname, filename)

 

 

轉自:https://www.cnblogs.com/hyacinthwyd/p/8997917.html

 

謝謝!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM