python list directory , subdirectory and files
- by thomytheyon
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