Friday, February 6, 2015

environment variables - Creating folder alias like %SystemRoot% in windows 7



I'm trying to create a shortened path to a directory that is nested in a lot of directories (ie C:\Users.......................................\TestApp\Data\32\TutorialData which is 80+ characters to %TestAPP%\Data\32\TutorialData).




I was able to accomplish this in part by using the setx command



setx TestApp "C:\Users\.......................................\TestApp"


Now when I navigate to %TestApp%\Data in explorer it opens up wonderfully, but it doesn't recognize the path in the open file dialog of other programs. Furthermore when explorer restarts the variable goes away. I tried



setx TestApp "C:\Users\.......................................\TestApp" /m



Which is supposed to set it as a system variable but then it doesn't load %TestApp%\Data because it says it can't find "C:\Users.......................................\TestApp /m\Data"



EDIT: (I only see this error from the open file dialog)



What do I need to do differently to accomplish this so it will work in open file dialogs and persist rebooting the computer?






I'm not sure at this point what happened before, in trying it on a separate computer / after reboot I didn't see that problem.




That said, I realized that this would not accomplish what I was hoping to anyways, because in open file dialogs %TestApp% still resolves to the full path, which I was hoping to shorten (I'm using an old program I don't have the code for that breaks because it only stores file paths in an array of 80 characters, additional ones are truncated).



The resulting questions that come up because of this are different enough from the original question it's not worth editing. The only thing to supplement would be if someone wanted to show how to have the variable persist, but it wouldn't serve to help me personally at this point, just potential future searchers.


Answer



I think you could benefit from using a junction point instead.
The tool you need is called 'mklink':



mklink /J C:\TestApp\ C:\..........\TestApp\



Then, navigate to C:\TestApp\ and you should see everything that exists in C:..........\TestApp\



This trick also works across different volumes.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...