Get absolute path of file why traversing through another directory
Question: I have a small snipped in python which intends to traverse through all the
directory , subdirectory and manitain a list of absolute path of all the files
.

code:

    
    
    import os , pickle
    root="/home/me/programs/"
    l = [] #Will have list of all the files parsed through
    for dname,subdirlist,flist in os.walk(root):
     for fname in flist:
      l.append(os.path.abspath(fname))
    

Even though i am parsing through all the files , my output is prefixing
`/home/me/programs/` irrespective of the actual absolute path.

For example, instead of having  
`'/home/me/programs/cpp/sample/test.c'`  
i will have `'/home/me/programs/test.c'`

How do i fix this problem ?


Answer: As mentioned in the [`os.walk`
doc](http://docs.python.org/library/os.html#os.walk), you'll have to join the
root path to your fname to get the absolute path :

    
    
    import os , pickle
    root="/home/me/programs/"
    l = [] #Will have list of all the files parsed through
    for dname,subdirlist,flist in os.walk(root):
        for fname in flist:
            l.append(os.path.join(dname, fname))
    

