def isdir(s): """Return true if the pathname refers to an existing directory.""" try: st = os.stat(s) except OSError: return False return stat.S_ISDIR(st.st_mode)