Skip to content

Instantly share code, notes, and snippets.

@davidallsopp
Created January 12, 2016 21:28
Show Gist options
  • Save davidallsopp/cc15ef3c4c32dec3778f to your computer and use it in GitHub Desktop.
Save davidallsopp/cc15ef3c4c32dec3778f to your computer and use it in GitHub Desktop.
Recursively find files from a starting directory, as a 1-line dictionary comprehension (or you could use a generator comprehension). Can easily add a filter using an "if" clause in the comprehension
>>> import os
>>> from os.path import join
>>> [join(dr,f) for dr, dirs, files in os.walk('test') for f in files if f.endswith('html')]
['test/t1.html', 'test/t2.html', 'test/subtest/t3', 'test/subtest/subsubtest/t6.html']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment