Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symlinks on windows

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

like image 421
Eugene Avatar asked Jun 18 '13 16:06

Eugene


People also ask

How do I view a symbolic link in Windows?

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.

Where are my symlinks Windows 10?

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.

How do I create a hard link in Windows?

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.

Are Windows shortcuts symlinks?

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.


1 Answers

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')
like image 130
Saullo G. P. Castro Avatar answered Oct 14 '22 16:10

Saullo G. P. Castro