I have a shortcut to a folder and I want to open it from the Command Prompt. I want the Command Prompt to immediately change to the target location of the shortcut. Instead, if I try to execute the shortcut at the Command Prompt it simply opens the folder in Windows Explorer.
How can I parse a shortcut file (.LNK) from the Command Prompt and switch to the shortcut's target folder?
Best Answer
This is a typical X-Y problem. If you want CMD to always open at a specific directory instead of the default, all you need to do is simply change the shortcut's properties as follows:
In Windows 7 the Command Prompt shortcut is typically located in
Start Menu > All Programs > Accessories
, so just right-click the shortcut, select Properties and edit the Start in field to your liking.You can also create a batch file named for example d.bat that contains a single line
cd /d c:\wamp\www
. Place the batch file somewhere in your path and now all you need to do is open CMD and type d to change to the specific directory. There are many more similar solutions as well.If you are dead set on parsing a shortcut (.LNK) file from the command prompt, save the following as ParseLnk.bat and execute it from the Command Prompt as
ParseLnk <LNK File>
: