The Computer Oracle

Checking where a symbolic link points at in Windows 7

-------------------------------------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
-------------------------------------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Darkness Approaches Looping

--

Chapters
00:00 Question
00:49 Accepted answer (Score 51)
01:12 Answer 2 (Score 6)
02:50 Answer 3 (Score 6)
04:11 Answer 4 (Score 2)
05:53 Thank you

--

Full question
https://superuser.com/questions/524669/c...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows7 #commandline #symboliclink

#avk47



ACCEPTED ANSWER

Score 54


The dir command dir /a can do this:

2012-12-26  09:30 PM    <DIR>          .
2012-12-26  09:30 PM    <DIR>          ..
2012-12-26  09:30 PM                 0 a.txt
2012-12-26  09:30 PM    <SYMLINK>      link.txt [a.txt]

Alternatively, you can use Windows Explorer:

Right click column, More, Link Target



ANSWER 2

Score 6


Copied from StackOverFlow, I just used this line, and it works

fsutil reparsepoint query "folder name" | find "Symbolic Link" >nul && echo symbolic link found || echo No symbolic link

Explanation:

From MSDN about FSUtil : Performs tasks that are related to file allocation table (FAT) and NTFS file systems, such as managing reparse points, managing sparse files, or dismounting a volume. If it is used without parameters, fsutil displays a list of supported subcommands.

For our use, we just care that it outputs a line that has "Symbolic Link" in it, if it's symbolic, which we then find, and if find succeeds, we output one thing, if it doesn't, we output something else.

Notes:

  • The quotes around the folder name are required if the path has spaces in it.
  • It gives the same output whether the folder doesn't exist, or isn't a symlink, use with caution.



ANSWER 3

Score 6


Using PowerShell, on at least Windows OS, you can find symbolic-links in any given directory, such as the following:

Get-ChildItem 'C:\nodejs\bin\' | Where-Object {$_.LinkType -eq 'SymbolicLink'}

A more concise alternative would be to use Get-ChildItem's alias ls:

ls 'C:\nodejs' -Attributes ReparsePoint -Recurse

And you can get relevant information on a symbolic-link by doing any of the following:

Get the file item and output its Target property. Target being the "value" of the symbolic-link. In an addition, method or command signatures for creating symlinks when juxtaposing between operating systems, the arguments names of: 'target', 'path' and/or 'value' may hold different meanings than another method signature on a different OS.

E:\AIT> Get-Item -Path 'C:\nodejs\bin\ionic.cmd' | Select-Object -ExpandProperty Target
E:\AIT\out\dependency_symlink.cmd

Get the file item and output its LinkType property. An item with a LinkType value of SymbolicLink means that its, well, symbolic.

E:\AIT> Get-Item -Path 'C:\nodejs\bin\ionic.cmd' | Select-Object -ExpandProperty LinkType
SymbolicLink

Get the file item and output its Mode property. An item with l in the Mode value indicates that it is a symbolic-link.

E:\AIT> Get-Item -Path 'C:\nodejs\bin\ionic.cmd' | Select-Object -ExpandProperty Mode
-a---l

Get the file item and output its Attributes property. An item attributed with a ReparsePoint value maybe indicative to a symbolic-link.

E:\AIT> Get-Item -Path 'C:\nodejs\bin\ionic.cmd' | Select-Object -ExpandProperty Attributes
Archive, ReparsePoint



ANSWER 4

Score 3


To check the location of Symlinks and Junction Points in Windows 7 or Windows 10...

Via Windows Explorer:

  1. Open the parent folder of the suspected symlink or junction point. (Note that symlinks and junction points get a shortcut icon applied in Windows 10 - not sure about Windows 7.)
  2. In the top of the Explorer window, in the row of column names, right-click and select "More...".

enter image description here

  1. Tick the box next to "Link Target" in the popup window that appears.

enter image description here

The path to the actual symlink location will be displayed in the Link target column that is added. Note that this only works for symlinks - not junction points:

enter image description here


Via Command Prompt:

  1. Navigate to the parent folder of the suspected symlink or junction point.
  2. Type dir /a.

A list of all files and folders will be displayed, including details of whether each is a symlink or junction point and where it points to:

enter image description here




ANSWER 5

Score 2


Do not use fsutil to check if an item is a symbolic link or not. At first because errorlevel has errors, so sometimes, it stays to 0 and a real folder is viewed as a symbolic link. Errorlevel can not be trusted.

A problem with find is because find "Symbolic Link" is possible in English, but not in other languages.

The good way is to search from the attributes :

for %%i in ("%file_to_test%") do set attribute=%%~ai
set attribute=%attribute:~8,1%
if "%attribute%" == "l" (
    echo It's a symlink!
) else (
    echo Damned! It's real!
)

Attributes got with %a are "drahscotlep" and "l" is for symbolic link.