I'm trying to check is the path symlink hardlink or junction point on windows
How can I do it? os.path.islink()
not work. It always returns False
I create symlinks by next method:
mklink /d linkPath targetDir
mklink /h linkPath targetDir
mklink /j linkPath targetDir
I've used command line because os.link and os.symlink available only on Unix systems
Maybe there are any command line tools for it? Thanks
In Command Prompt, run this command: dir /AL /S c:\ A list of all of the symbolic links in the c:\ directory will be returned.
Symbolic links work in the Save and Open dialog boxes of your applications. If you work from the command prompt, you'll discover that you can access symbolic link folders on the command line, as shown in Figure D. You can't really use a shortcut from the command line.
To create a file hard link: mklink /H linkName target. To create a directory junction: mklink /J linkName target. To create a directory symbolic link: mklink /D linkName target. To create a file symbolic link: mklink linkName target.
The work difference between a Linux symlink and a Windows shortcut is that a shortcut takes you to the destination location whereas the symlink brings the destination to where the link is. A symbolic link is a pointer that works at the file-system level as it opposed to a shortcut in windows.
The os.path.islink()
docstring states:
Test for symbolic link.
On WindowsNT/95 and OS/2 always returns false
In Windows the links are ending with .lnk
, for files and folders, so you could create a function adding this extension and checking with os.path.isfile()
and os.path.isfolder()
, like:
mylink = lambda path: os.path.isfile(path + '.lnk') or os.path.isdir(path + '.lnk')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With