Windows native alternative for ln -s is mklink.
Is there any native alternative for readlink? Or how to natively identify if the file is symlink?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t believe there’s any tool directly equivalent to
readlink. But you can see in the output ofdirwhether an item is a symlink or not, so you can still determine this from the command line or in a script.Test whether it’s a symlink or not
You can pretty easily test whether a given file is a symlink using syntax like:
Errorlevel will be 0 in the case that “
<SYMLINK>” is found, and will be 1 otherwise.Determine the target of a symlink
Determining the actual target of the symlink is another matter, and in my opinion not as straight-forward. The output of
dir mysymlink | find "<SYMLINK>"might look likeYou can parse this, but some of the characters make it difficult to deal with all in one variable, so I found it easier to deal with a temporary file:
This yields output like
[C:\Windows\Temp\somefile.txt]. (Remember to use%%iwithin any batch scripts; the above is from the command prompt.)To get the result without the brackets, you can do something like:
The variable
%answer%contains the result with the brackets, so%answer:~1,-1%is the result without the first or the last character.