~ Mayank Johri’s Tips ~

July 2, 2008

recursive list files in a dir using Python

Filed under: Python — mayankjohri @ 8:31 pm
Tags: ,

use the following code to list the files in a dir tree

import os
import sys
fileList = []
rootdir = sys.argv[1]
for root, subFolders, files in os.walk(rootdir):
    for file in files:
        fileList.append(os.path.join(root,file))
print fileList

1 Comment »

  1. [...] Original post [...]

    Pingback by ownport.net » Blog Archive » recursive list files in a dir using Python — October 6, 2008 @ 5:32 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.