Created
November 23, 2010 21:49
-
-
Save bussiere/712605 to your computer and use it in GitHub Desktop.
listing files in a directory recursivly not my creation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import stat | |
def walktree (top = ".", depthfirst = True): | |
names = os.listdir(top) | |
if not depthfirst: | |
yield top, names | |
for name in names: | |
try: | |
st = os.lstat(os.path.join(top, name)) | |
except os.error: | |
continue | |
if stat.S_ISDIR(st.st_mode): | |
for (newtop, children) in walktree (os.path.join(top, name), depthfirst): | |
yield newtop, children | |
if depthfirst: | |
yield top, names | |
for (basepath, children) in walktree("C:/Users/Bussiere/Documents/docinfo",False): | |
for child in children: | |
print (os.path.join(basepath, child).replace("C:/Users/Bussiere/Documents/docinfo","")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment