How to filter files (with known type) from os.walk?

后端 未结 10 1155
北海茫月
北海茫月 2020-12-24 12:10

I have list from os.walk. But I want to exclude some directories and files. I know how to do it with directories:

for root, dirs, files in os.wa         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 12:54

    And in one more way, because I just wrote this, and then stumbled upon this question:

    files = filter(lambda file: not file.endswith('.txt'), files)

提交回复
热议问题