Recursively find list of files in a directory in Python 2.2

I have been using python for writing small utility programs. Till now I avoided scripting languages like python because I though shell script is master of everything and works in any linux computer. They also have all programming constructs like loops and conditions etc. However when it came to quickly get some work done, shell script too a lot of time write a error free program. Finally I jumped to python to do some file batch processing.

The most fundamental need to batch file processing is to iterate through all the files in a given directory. I could found several ways to do so using os.walk function but my old linux server had only Python 2.2 and I did not want to FTP files to my local PC to server back and fourth . So here is the code which also works in old version of python.

[code language="python"]
import os

# finds all the files in a directory recursively
def listAll(dirName):
files = os.listdir(dirName)
for f in files:
if os.path.isfile(os.path.join(dirName,f)):
return filelist1
# root directory path
rootdir= '/home/'

for f in listAll(rootdir):
print "Absolute Path " + os.path.abspath(f)
print "File Name" + os.path.basename(f)
print "Directory Path" + os.path.dirname(f)
# Change directory
# print current directory
print os.getcwd()
# check file extension
if not ( f.endswith(".java") or or f.endswith(".xml")):
# Do nothing



  1. ...Check this out

    [...]Wow, awesome blog layout! How long have you been blogging for?[...]

  2. ...Links

    [...] What web host are you the usage of? Can I get affiliate hyperlink to your host? I wish web site loaded up as quickly as yours lol[...]

  3. ...Visitor recommendations

    [...]Wow, wonderful blog layout! How long have you been blogging for?[...]

  4. Hello, how's it going? Just shared this post with a colleague, we had a good laugh.
    Cheap Louis Vuitton planner

  5. Hello there, I found your blog by the use of Google at the same time as searching for a related topic, your web site came up, it seems great. I have bookmarked it in my google bookmarks.
    Cheap Louis Vuitton mini lin


Post a Comment

Popular posts from this blog

Bengali English word definition in Google Dictionary

Trace India Mobile Number

Load Testing Using Gatling