def one_file_or_folder(folder):
 if (os.path.exists(folder) and os.path.isdir(folder)):
  cont = os.listdir(folder)
  if (len(cont) == 1):
   folder = os.path.join(folder, cont[0])
   folder = one_file_or_folder(folder)
 return folder

def one_file_or_folder ( folder ) : if ( os . path . exists ( folder ) and os . path . isdir ( folder ) ) : cont = os . listdir ( folder ) if ( len ( cont ) == 1 ) : folder = os . path . join ( folder , cont [ 0 ] ) folder = one_file_or_folder ( folder ) return folder
if the dir only contains one file or folder .