I have 2 directories left and right that contain files: image1.jpg, image4.jpg, image2.jpg ... image131.jpg
I'd like to put those names in sorted lists all
, left_files
, right_files
.
The following program makes unordred lists all
, left_files
, right_files
:
all = []
left_files = []
right_files = []
if os.path.exists(dir):
for path, names, files in os.walk(dir):
names.sort()
for f in files:
if os.path.splitext(f)[1] in ['.bmp', '.png', '.jpg', '.ppm']:
if 'left' in f or 'left' in path:
left_files.append( os.path.join( path, f ) )
elif 'right' in f or 'right' in path:
right_files.append( os.path.join( path, f ) )
all.append( os.path.join( path, f ) )
When I use sorted(left_files)
, it gives me files image1.jpg, image10.jpg, image100.jpg
, but I want to obtain image1.jpg, image2.jpg, image3.jpg...