Please use below:
out_directory = os.path.normpath(out_directory)
mode = os.path.basename(out_directory)