python獲取目錄下指定後綴名的文件

import os
all_file_list =[]
## 獲取路徑下的png文件
def get_all_filepath(dir):
    parents = os.listdir(dir)
    for parent in parents:
        child = os.path.join(dir,parent)
        if os.path.isdir(child):
            get_all_filepath(child)
        else:
            suffix = os.path.splitext(child)[1]
            #print(suffix)
            if suffix ==".png":
                all_file_list.append(child)

 

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