import os
def dir_list2(dir_name, *args):
fileList
= []
for file in os.listdir(dir_name):
dirfile
= os.path.join(dir_name,
file)
if os.path.isfile(dirfile):
if len(args) == 0:
fileList.append(dirfile)
else:
if os.path.splitext(dirfile)[1][1:]
in args:
fileList.append(dirfile)
elif
os.path.isdir(dirfile):
print
"Accessing directory:", dirfile
fileList += dir_list2(dirfile,
*args)
return fileList
if __name__ == '__main__':
dir_name = (os.path.join('C:\\', '
fileList
= dir_list2(dir_name, 'py', 'txt')
for f in fileList:
print f#, os.path.getsize(f), os.path.getmtime(f)