| 1 |
import os |
| 2 |
|
| 3 |
def collect_files(path): |
| 4 |
'''Given a path to a file, yield that path. Given a path to a directory, |
| 5 |
yield the path of all files within that directory recursively, omitting any |
| 6 |
that begin with a period (.) character.''' |
| 7 |
|
| 8 |
if os.path.isfile(path): |
| 9 |
yield path |
| 10 |
return |
| 11 |
|
| 12 |
if not os.path.isdir(path): |
| 13 |
raise ValueError('Not found: "%s"' % path) |
| 14 |
|
| 15 |
for root, dirs, file_names in os.walk(path): |
| 16 |
for file_name in file_names: |
| 17 |
if file_name.startswith('.'): |
| 18 |
continue |
| 19 |
|
| 20 |
yield os.path.join(root, file_name) |