I try since a while to get all names of files with a certain extension (let's say .txt) in a folder. I found a lot of close topics online but never what I wanted to do.
The closest I've reach is by using:
listFiles = glob.glob(sourdir + '/*.txt')
or
files = fnmatch.filter(os.listdir(sourdir+"/"), "*.txt")
or
[s for s in os.listdir(sourdir+"/") if s.endswith('.txt')]
which gives me all the .txt files in a certain folder. HOWEVER, it automatically sort the files ! In my folder I have :
file0.txt, file1.txt, file2.txt, file3.txt, ...
And with anything that give me those files I have something like :
file0.txt, file1.txt, file10.txt, file11.txt, ...
I just want to read the name of the file in the same order in which they are in the folder ! How is it so hard to do simple things..
If I do os.listdir(sourdir+"/")[i] in a loop, I can see that the listdir check the file in the correct order not the sorted one. However I didnt not success to use "os.listdir(sourdir+"/")[i]" in a loop AND filtering by .txt in the same time.
If someone could help me I really don't know what to do now