How do you walk through the directories using python?

前端 未结 4 1486
长情又很酷
长情又很酷 2020-12-15 17:23

I have a folder called notes, naturally they will be categorized into folders, and within those folders there will also be sub-folders for sub categories. Now my problem is

4条回答
  •  北海茫月
    2020-12-15 17:44

    Based on your short descriptions, something like this should work:

    list_of_files = {}
    for (dirpath, dirnames, filenames) in os.walk(path):
        for filename in filenames:
            if filename.endswith('.html'): 
                list_of_files[filename] = os.sep.join([dirpath, filename])
    

提交回复
热议问题