[Level 2] Recursive directory list

#!/bin/env python
import os, sys
wholeFileList = []
baseDir = sys.argv[1]
for parentDir, childDirList, fileList in os.walk(baseDir):
    for file in fileList:
        wholeFileList.append(os.path.join(parentDir,file))
for file in wholeFileList:
    print file
# ./t.py /tmp/d
/tmp/d/1.txt
/tmp/d/2/6.txt
/tmp/d/2/3/a.txt
/tmp/d/2/4/b.txt
/tmp/d/2/5/c.txt
Wish this helps. regards, Stanley Huang

Comments

Popular posts from this blog

[Level 2] Shell Interactive With Zenity Episode 5 -- list

[Level 2] iif in Python