Browse files and subfolders in Python

前端 未结 5 1815
有刺的猬
有刺的猬 2020-11-28 03:29

I\'d like to browse through the current folder and all its subfolders and get all the files with .htm|.html extensions. I have found out that it is possible to find out whet

5条回答
  •  执笔经年
    2020-11-28 04:10

    Slightly altered version of Sven Marnach's solution..

    
    import os

    folder_location = 'C:\SomeFolderName' file_list = create_file_list(folder_location)

    def create_file_list(path): return_list = []

    for filenames in os.walk(path): for file_list in filenames: for file_name in file_list: if file_name.endswith((".txt")): return_list.append(file_name) return return_list

提交回复
热议问题