Skip to content

Instantly share code, notes, and snippets.

@zhanglintc
Last active November 30, 2019 09:24
Show Gist options
  • Save zhanglintc/c9b112a915316b3805fa to your computer and use it in GitHub Desktop.
Save zhanglintc/c9b112a915316b3805fa to your computer and use it in GitHub Desktop.
yield each file's path in a given folder
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def each_file(target):
for root, dirs, files in os.walk(target):
for f in files:
yield os.path.join(root, f)
def each_file(t):
import os
return (os.path.join(root, f) for root, _, fs in os.walk(t) for f in fs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment