def get_closest_dir(workdir):
 closest_dir = ''
 for wdi in path_split_all(workdir):
  if os.path.isdir(os.path.join(closest_dir, wdi)):
   closest_dir = os.path.join(closest_dir, wdi)
  else:
   break
 assert (closest_dir != workdir)
 return (closest_dir, wdi)

def get_closest_dir ( workdir ) : closest_dir = '' for wdi in path_split_all ( workdir ) : if os . path . isdir ( os . path . join ( closest_dir , wdi ) ) : closest_dir = os . path . join ( closest_dir , wdi ) else : break assert ( closest_dir != workdir ) return ( closest_dir , wdi )
returns the topmost already-existing directory in the given path erasing work-dirs should never progress above this file .