class sorter_ByNameRev: def __call__( self, left, right ): if left.isdir() and not right.isdir() : return -1 elif not left.isdir() and right.isdir() : return 1 return -cmp( left.name.lower(), right.name.lower() ) class sorter_ByExtRev: def __call__( self, left, right ): if left.isdir() and not right.isdir() : return -1 elif not left.isdir() and right.isdir() : return 1 cmp_result_ext = cmp( os.path.splitext(left.name)[1].lower(), os.path.splitext(right.name)[1].lower() ) if cmp_result_ext : return cmp_result_ext return -cmp( left.name.lower(), right.name.lower() )