【轉】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)

 

 

轉自:http://www.javashuo.com/article/p-tptwqweq-bw.htmlhtml

 

謝謝!app

相關文章
相關標籤/搜索