79570878

Date: 2025-04-12 19:59:01
Score: 2
Natty:
Report link

I have reviewed the information suggested by @Brendan Mitchell, @Mark Tolonen and @JonSG, thank you.

I would like to accept their comments as an answer because a Windows shortcut created by windows explorer is a special file, not a symlink or a junction.

That means that os.scandir [os.listdir, et al] will not follow the *.lnk file, even if the parameter "follow_symlinks=True". I also cannot find any windows stat().st_file_attribute that would indicate that the file is a shortcut.

So the only way to determine a shortcut is by comparing the file extension:

if os.path.splitext(filename)[1] == ".lnk"

or

if filename[-4:] == ".lnk"

Determining the target of a shortcut has been discussed elsewhere.

Reasons:
  • Blacklisted phrase (0.5): thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Brendan
  • User mentioned (0): @Mark
  • User mentioned (0): @JonSG
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: at2010