Test whether a path is a symbolic link
(path)
| 162 | # This will always return false on systems where os.lstat doesn't exist. |
| 163 | |
| 164 | def islink(path): |
| 165 | """Test whether a path is a symbolic link""" |
| 166 | try: |
| 167 | st = os.lstat(path) |
| 168 | except (OSError, ValueError, AttributeError): |
| 169 | return False |
| 170 | return stat.S_ISLNK(st.st_mode) |
| 171 | |
| 172 | # Being true for dangling symbolic links is also useful. |
| 173 |