I have a folder where I have names as
file_1.txt,file_2.txt,file_3.txt,file_10.txt,file_100.txt.
I am reading these files using os.walk.i want print file names in a sorted order.My code is as follows:
import os
import fnmatch
rootDir = "lecture1"
for root, dirs, files in os.walk(rootDir):
files = sorted(files)
for file in fnmatch.filter(files, '*.wav'):
print os.path.join(rootDir, file)
But the above code is not printing the file in a sorted order.please suggest me a way so that i can print it in a sorted order as follows:
file_1.txt,file_2.txt,file3_txt,file_10.txt,file_100.txt
Currently its printing
file_1.txt,file_1.txt,file_100.txt,file_2.txt,file_3.txt