Monday, November 26, 2007

I started a dull day doing lot of mistakes! But managed to code something on Python for file processing. I tried to traverse through the directory getting all the input files and adding it to the list.

def prepareListOfFiles(dir):
for f in os.listdir(dir):
if os.path.isdir(dir + f) == True:
prepareListOfFiles(dir + f + '\\')
else:
listOfFiles.append(dir+f)

And to delete a list of files of the given pattern, I wrote:

def cleanOldOutputFiles(dir):
for f in os.listdir(dir):
if os.path.isdir(dir + f) == True:
cleanOldOutputFiles(dir + f + '\\')
else:
if f.endswith('.output'):
os.remove(dir+f)

Remember I am new to Python !

No comments: