I am trying to read all files within a directory.
for root, dirs,files in os.walk(path):
for j in files:
print(str(j))
This is my code where path
is the path of the directory to be read.But it does not print the files in the order of their names. In my case, I have files from 0.txt
,1.txt
,.... to 3590.txt
. I want it to print the files in the same order. But rather it starts from 579.txt
. How can I fix this? I want to do some computation on the files in the same order and so just storing the names in a list and sorting it wont help.