When doing recursive directory traversal, sometimes you want to follow symlinks that point at other directories, and sometimes you don’t. Here’s a routine that you can use to check whether a path specifies a directory, with the option to treat a symlink to a directory as a directory, or not:
import os import stat def isdir(path, followsymlink) : """returns true iff path specifies a directory. A symlink is followed iff followsymlink.""" return stat.S_ISDIR((os.lstat, os.stat)[followsymlink](path).st_mode) #end isdir -- http://mail.python.org/mailman/listinfo/python-list