Yes, the folders are found using
classes = [d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))]
classes.sort()

The .sort() call sorts the folders in alphabetic order.
You can find the code here 54.