python list directory , subdirectory and files
Posted
by thomytheyon
on Stack Overflow
See other posts from Stack Overflow
or by thomytheyon
Published on 2010-05-26T03:38:04Z
Indexed on
2010/05/26
3:41 UTC
Read the original article
Hit count: 262
Hi Alls,
I'm trying to make a script to list all directory, subdirectory, and files in a given directory. I tried this :
import sys,os
root="/home/patate/directory/"
path=os.path.join(root,"targetdirectory")
for r,d,f in os.walk(path):
for file in f: print os.path.join(root,file)
Unfortunatly it doesn't work properly, i get all the files, but not them complete path. like : if the dir struct would be :
/home/patate/directory/targetdirectory/123/456/789/file.txt
It would print:
/home/patate/directory/targetdirectory/file.txt
What i need is the first result, any help would be greatly appreciated !
Thanks
© Stack Overflow or respective owner