Alex Rivera | Logout

Get absolute paths of all files in a directory

Asked 2012-03-22T05:16:01.977
117

How do I get the absolute paths of all the files in a directory that could have many sub-folders in Python?

I know os.walk() recursively gives me a list of directories and files, but that doesn't seem to get me what I want.

Edit
Report

1 Answer

10

Try:

import os

for root, dirs, files in os.walk('.'):
    for file in files:
        p=os.path.join(root,file)
        print p
        print os.path.abspath(p)
        print
answered 2012-03-22T05:25:52.800

Your Answer