I want to get the list of all file names in a directory but the order of files matters to me. (And I'm using Google Colab if that matters)
P.S: I've accepted the first answer, but just in case know that when I moved my files from google drive to my local PC and run the code, it worked and printed those with the original order. I think there is something with the Google Colab
Suppose my files are in this order in my directory:
file1.txt
file2.txt
file3.txt
...
filen.txt
P.S: These file names are just examples to be clear. In reality my filenames don't have any pattern to be sorted, they are like
1651768933554-b6b4deb3-f245-4763-b38d-71a4b19ca948.wav
When I get the file names via this code:
import glob
for g in glob.glob(MyPath):
print(g)
I'll get something like this:
file24.txt
file5.txt
file61.txt
...
I want to get the file names in the same order they are in the folder.
I searched as far as I could but I didn't find any SO post solving my problem. Appreciate any help.
P.S: I tried from os import listdir too but didn't work.