Is It A Directory

  • Thread starter Lawrence D'Oliveiro
  • Start date
L

Lawrence D'Oliveiro

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top