nested list comprehension with os.walk

后端 未结 2 736
傲寒
傲寒 2021-02-04 11:56

Trying to enumerate all files in a certain directory (like \'find .\' in Linux, or \'dir /s /b\' in Windows).

I came up with the following nested list comprehension:

2条回答
  •  旧时难觅i
    2021-02-04 12:06

    it is:

    allfiles = [join(root, f) for _, dirs, files in walk(root) for f in files]
    

提交回复
热议问题