Mailing List Archive

Symbolic links on Windows
Hello,

It seems that symbolic links on Windows are not
well reconized by modules os or pathlib.

I have a file named json.txt on my destop. With a
drag and drop right click on it I create a link
automatically named: json.txt - Raccourci.lnk

Then:

>>> from pathlib import Path

>>> p2 = Path('C:/Users/jm/desktop/json.txt - Raccourci.lnk')

>>> p2
WindowsPath('C:/Users/jm/desktop/json.txt - Raccourci.lnk')

>>> p2.exists()
True

>>> p2.is_file()
True

>>> p2.is_symlink()
False

With this last command I was expecting True and for
p2_is_file() I was expecting False



With os, it's the same

import os

>>> os.path.exists(p2)
True

>>> os.path.isfile(p2)
True

os.path.islink(p2)
False


What's wrong plz ?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Symbolic links on Windows [ In reply to ]
Le 17/11/2021 à 13:10, Python a écrit :
> ast wrote:
>> Hello,
>>
>> It seems that symbolic links on Windows are not
>> well reconized by modules os or pathlib.
>>
>> I have a file named json.txt on my destop. With a
>> drag and drop right click on it I create a link
>> automatically named: json.txt - Raccourci.lnk
>
> This is not a symbolic link.
>
> Symbolic links were introduced in Windows Vista/Windows
> Server 2008. A .lnk file is just a regular file containing
> the path of the target (you can open it and read it if you
> wish) that is interpreted in a specific way by the graphical
> Shell and some other applications.
>
>

Yes you are right

On Windows symbolic links are created in a cmd tool:
e.g

mklink json2.txt json.txt

And it is something different than shortcut files (suffix .lnk)
--
https://mail.python.org/mailman/listinfo/python-list