# check if a (file or directory) symbolic links exists on a windows file system with the help of win\_file

**URL:** <https://forum.ansible.com/t/check-if-a-file-or-directory-symbolic-links-exists-on-a-windows-file-system-with-the-help-of-win-file/20885>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [March 16, 2016, 9:56am UTC](https://forum.ansible.com/t/check-if-a-file-or-directory-symbolic-links-exists-on-a-windows-file-system-with-the-help-of-win-file/20885 "2016-03-16T09:56:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [March 16, 2016, 9:56am UTC](https://forum.ansible.com/t/check-if-a-file-or-directory-symbolic-links-exists-on-a-windows-file-system-with-the-help-of-win-file/20885/1 "2016-03-16T09:56:05Z")

</div>

I am trying to gather custom facts for a windows 2012 R2 server while avoiding to write powershell scripts. win\_stat is something that can apparently be very useful to me but i am getting confused about its exact behavior.  
I have a file structure like this:

E:  
E:\link1  
E:\folder\link2

E:\folder\link2\some\_dir\link3.jar

Link1 and 2 are directory symbolic links and link3 is a file symbolic link and is currently active in a java process. I am trying to check if these links exists or not via this kink of script:

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [March 16, 2016, 10:01am UTC](https://forum.ansible.com/t/check-if-a-file-or-directory-symbolic-links-exists-on-a-windows-file-system-with-the-help-of-win-file/20885/2 "2016-03-16T10:01:39Z")

</div>

1. I have a file symbolic link E:\folder\link.exe pointing to an exe file and this link is not actively in use by a process. So when i use

win\_stat: path=“E:\folder\link.exe”

i get an answer that it does not exist.

“msg”: {  
“changed”: false,  
“stat”: {  
“exists”: false  
}  
}

But when i use:

win\_stat: path=“E:\folder\link.exe”

I get a proper result.  
Probably related to the above questions, but **what is the proper syntax to specify a path here ?**

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [March 17, 2016, 10:07am UTC](https://forum.ansible.com/t/check-if-a-file-or-directory-symbolic-links-exists-on-a-windows-file-system-with-the-help-of-win-file/20885/3 "2016-03-17T10:07:14Z")

</div>

I don’t have any experience of using symlinks on windows, but my advice for construction windows paths (assuming you are using ansible 2.0 or later) is…

1/ If you need to double quote your path names, then always use double backslash for the path separator

So  
win\_stat: “path=E:\folder\link.exe”

2/ I would also advise using the ‘yaml style’ way of supplying module parameters, rather than using the key=value style, if only because ‘yaml style’ makes you put 1 parameter per line, which often means you don’t need to use any quotes at all for hard-coded windows paths:

So like this (yaml style parameter)  
win\_stat:  
path: E:\folder\link.exe

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [March 17, 2016, 10:14am UTC](https://forum.ansible.com/t/check-if-a-file-or-directory-symbolic-links-exists-on-a-windows-file-system-with-the-help-of-win-file/20885/4 "2016-03-17T10:14:32Z")

</div>

Thanks for the answer. I figured i should always quote and use double slashes to be on safe side.  
I am still stuck with problem number 3. can you help me with that ?
