Python sorted order of files
<p>I have written the following code for a program to display the image path names in a folder. However, as seen in the output, the pictures' paths are not being displayed in the correct order despite me using sorted. How can I display them in their sorted order?</p>

<p>Code:</p>

<pre><code>import os
import sys
from PIL import Image
import PIL.ImageOps
import glob

path="/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/"
print(path)
files=sorted(glob.glob(path+"*.JPG"))
#print(files)
file_index=0
for f in files:
    file_index=file_index+1
    print(f,file_index)
</code></pre>

<p>Output:</p>

<pre><code>/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/1.JPG 1
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/10.JPG 2
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/11.JPG 3
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/12.JPG 4
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/13.JPG 5
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/14.JPG 6
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/2.JPG 7
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/3.JPG 8
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/4.JPG 9
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/5.JPG 10
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/6.JPG 11
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/7.JPG 12
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/8.JPG 13
/home/srilatha/Desktop/Research_intern/Data_sets/Expanded_data_set/1/9.JPG 14
</code></pre>