import glob
for file in glob.glob('images/scratch_assay/*[0-9].*'):
print(file)
Asked
Active
Viewed 31 times
0

Manvith Penklagar
- 13
- 3
-
"it should start from 1 to 10" - Why would it do that? – trent Sep 27 '22 at 13:07
-
Does this answer your question? [How are glob.glob()'s return values ordered?](https://stackoverflow.com/questions/6773584/how-are-glob-globs-return-values-ordered) – w-m Sep 27 '22 at 13:10
-
As you don't have leading zeroes, you will to perform a natural sort on your list of file paths. – w-m Sep 27 '22 at 13:12
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 27 '22 at 15:54
1 Answers
0
You can sort the returned list with sorted(glob.glob('images/scratch_assay/*[0-9].*'))
But consider that sorting alphabetically means that "10" will come just after "1", so the sequence will be 1, 10, 2, 3, 4, 5, 6, 7, 8, 9
To avoid that the simplest way is probably to pad the filenames with a leading zero ("01", "02", "03", etc)

Liutprand
- 527
- 2
- 8