Program for recursively printing files and directory in python #!/usr/bin/env python
import os
temp_path = os.getcwd()
path = temp_path.split("/")
print path[-1]
def recursive(wrkdir):
for items in os.listdir(wrkdir):
if os.path.isfile(items):
print "---"+items
for items in os.listdir(wrkdir):
if os.path.isdir(items):
print "---"+items
#following call to recursive function doesn't work properly
recursive("./"+items)
recursive(os.getcwd())
"./"+itemsis only going to be the path to the folder in the first level of the recursion. Maybeos.path.join(wrkdir, items)os.path.isdir, you need to provide the full path./fol1, and not the full path. Printwrkdirif you want to be sure.