Open the file for writing and reading.
import os
input = open(filename, 'r') # read
output = open(filename, 'w') # write
output = open(filename, 'a') # write more
Walk the whole folder
for root, dirs, files in os.walk(path, topdown=False):
#hanlde file
for name in files:
if name[:-3] = 'exe':
print name
Delete Files
top='mydata/'
for root,dir,files in os.walk(top,topdown=False):
for name in files:
os.remove(os.path.join(root,name))
os.rmdir('mydata')
os.mkdir('mydata')