Can I create a shortcut to a Windows directory?

I would like a quick command line-based way to get to a directory I use all the time. Is there a way to create some kind of alias in Windows so that I can type, for example, VS08P at a command prompt or in the address bar and Windows will automatically open the folder I want, which is c:\Documents and Settings\[My ID]\My Documents\Visual Studio 2008\Projects?

(Note that the question isn't about what to do with Visual Studio 2008. Unless the solution is a batch file, I think I've asked the question on the right site.)


Solution 1:

If you want to open that folder in Windows Explorer, you can either:

  1. Create a shortcut (.lnk file) to a folder (by right clicking > New > Shortcut in Windows Explorer or on your desktop) then drop that shortcut somewhere in your path.
  2. Create a batch file like this:

    cd "c:\Documents and Settings\etc\etc"
    start .
    

    then save it as VS08P.bat and put it somewhere in your path.

If you want to jump to it in your command prompt, see Phoshi's answer.

Solution 2:

Use the mklink command. From the command-line:

C:> mklink /D VS08P c:\Documents and Settings\[My ID]\My Documents\Visual Studio 2008\Projects

You will now have c:\VS08P that points to your Visual Studio directory above.

Solution 3:

I will add to the 'create a simple batch' cacophony, with a twist. You can create a simple batch, but put a switch in side, such that you can use it to navigate to variety of favorite dirs:

@echo off
GOTO %1
:VS08P
cd c:\Documents and Settings\[My ID]\My Documents\Visual Studio 2008\Projects
GOTO END
:music
cd "C:\Documents and Settings\[My ID]\My Documents\My Music"
GOTO END
:downloads
cd C:\shared\downloads
GOTO END
:logs
cd C:\[project path]\logs
GOTO END
:END

You can call it go.bat, and you can use it for all your favorite locations Your friends will think you are really cool because you can just type go logs on the commandline and you are magically taken to your logs directory. You will still need to append the dir within which this bat is saved to your PATH.

Solution 4:

The solution is probably a batch file. Make a VS08P.bat in system32 (normally :\windows\system32) that contains:

@ECHO OFF
cd c:\Documents and Settings\[Your ID]\My Documents\Visual Studio 2008\Projects\

Then, typing VS08P should take you there.

Solution 5:

You could set a custom environment variable:

  • Right-click "My Computer" and select "Properties"
  • Select the tab "Advanced"
  • Click the button "Environment variables"
  • At the top part of the window you can define your own system variables

I have a German Windows installation so the names of the items mentioned above can be slightly different ;)

Another way would be:

Create a batch with the following content and run the shell through this:

@echo off
set VS08P = c:\Documents and Settings\[My ID]\My Documents\Visual Studio 2008\Projects
cls

This way you can add as many vars as you like and call them inside your shell session.