Using Python, I need to check if hundreds of symbolic links are correct and recreate them when not. Now I have to compare the real paths of what I want and what I have, but it is slow because it is over NFS with auto-mount.
Otherwise, I will start the subprocess using the ls -l command and work in the list of returned strings. I would prefer a better solution using the Python library ...
Edit1: I have: link_name -> link_target , and then link_target -> a_real_file . I need to extract link_target from link_name , not a_real_file . I don't care if there is a real file.
Edit2: Maybe I didn’t put it right. What I mean by a valid symbolic link is "a link that points to a predefined path, even if it does not exist." Therefore, I need to verify that:
link_name_1 -> target_1 link_name_2 -> target_2
This is why I need to extract goals, not real paths. Then I compare them with a link (dictionary). So my question is: how to extract the target path?
source share