Find broken symlinks with Python

后端 未结 8 1468
广开言路
广开言路 2020-12-15 05:17

If I call os.stat() on a broken symlink, python throws an OSError exception. This makes it useful for finding them. However, there are

8条回答
  •  无人及你
    2020-12-15 05:22

    os.path

    You may try using realpath() to get what the symlink points to, then trying to determine if it's a valid file using is file.

    (I'm not able to try that out at the moment, so you'll have to play around with it and see what you get)

提交回复
热议问题