I have added support for Windows symbolic links in our application using the CreateSymbolicLink function. Our application stores data across a set of actual folders. Our users needed to store some folders outside of one main root folder. The solution we chose was symbolic links. This lets them do things like keep a subset of data in DropBox or stored out on a network drive. So far everything has been working great.
When using Windows Explorer, Windows will show the following message if the link target is not present. This could be caused by a target being renamed or a remote network drive not being available.
Location is not available
C:...\MyLink refers to a location that is unavailable. It could be on a hard drive on this computer, or on a network. Check to make sure that the disk is properly inserted, or that you are connected to the Internet or your network, and then try again. If it still cannot be located, the information might have been moved to a different location.
I am trying to duplicate this check and add the target location so users can tell why no data is present.
A normal directory exists check is not sufficient because the symbolic link is present on the system. I have worked around this by calling CreateFile to open the folder. This causes the target location to be opened instead of the symbolic link. This does fail as needed for my check. Now I am stuck trying to get the target path that the link points to.
I have found this answered Stack Overflow question for reading the Target Location from a symbolic link.
- How do I programmatically access the target path of a windows symbolic link?
However that answer requires a valid handle from opening the directory. In my case I want to find the name for a broken link to help with trouble shooting and fixing the link.
How can I get the target location of a symbolic link without a valid handle?