10

I have to switch to Windows for the duration of a project.

I have only just started, and I already dislike using cmd.

Is there a shortcut for C:\Users\<current user>\Documents\ ?

11

4 Answers 4

23

Is there a shortcut for C:\Users\<current user>\Documents\?

There is no direct shortcut.

There are a couple of different solutions (see below).

  1. Use an environment variable together with cd or cd /d

  2. Use subst or net use to creating a mapping to another drive letter.

  3. Install cygwin and use bash

  4. Use powershell - powershell supports ~

The last solution is probably the simplest if you are prepared to use powershell instead of cmd.


Solution 1: Use an environment variable together with cd or cd /d

If you want to change to this directory on a regular basis then run the following command:

setx DOCS %USERPROFILE%\Documents

This will permanently set the environment variable DOCS, but in order to use use it you need to first start a new cmd shell, then the variable is defined and ready to use:

F:\test>echo %DOCS%
C:\Users\DavidPostill\Documents

To change directory from any location use the following command:

cd /d %DOCS%

If you are already on drive c: you can just use:

cd %DOCS%

Create a batch file (docs.cmd) and put it somewhere in your PATH.

docs.cmd:

@echo off
cd /d %DOCS%

You can then just type docs regardless of your current location and it will take you to C:\Users\<current user>\Documents\


Solution 2: Use subst or net use to creating a mapping to another drive letter.

You can use subst:

subst x: %USERPROFILE%\Documents

And then

x:

Unfortunately drive mappings do not persist across reboots.

net use will persist across reboots, for example:

net use x: "\\computerName\c$\pathName" /persistent:yes

See the answers in How to make SUBST mapping persistent across reboots? for detailed instructions.


Solution 3: Install cygwin and use bash

Only just started, already hate cmd

You could consider installing cygwin:

Cygwin is:

  • a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.

Once you have installed cygwin you can run bash in a cygwin terminal.

Alternatives to cygwin include msys (MingW):

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.

And Git for Windows:

Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.


Solution 4: Use powershell

As pointed out in a comment by SBI powershell supports ~ and you can just type:

cd ~/documents

If you have strange characters in your user name (for example if your user name is an email address) then quote as follows:

cd "~/documents"

But also I need to be able to run a shortcut!

However, to run Intel's icl, I require a shortcut to C:\Windows\SysWOW64\cmd.exe /E:ON /V:ON /K ""C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016.2.180\windows\bin\ipsxe-comp-vars.bat" ia32 vs2015".

Does powershell provide the necessary options as well?

You can create a shortcut as normal to run the above command.

Then execute the shortcut from powershell, for example:

 Invoke-Item -Path C:\Users\Dex\Desktop\Notepad++.lnk 

And:

 Start-Process -FilePath  C:\Users\DDhami\Desktop\Notepad++.lnk 

Source PowerShell trick : Execute .lnk file.


Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • cd - Change Directory - Select a Folder (and drive)
  • setx - Set environment variables permanently, SETX can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU).
  • subst - Substitute a drive letter for a network or local path.
9
  • You could also subst mount the directory as a volume.
    – paradroid
    Mar 4, 2016 at 11:30
  • @paradroid Yes, but subst does not persist if you reboot. There is a workaround for this (see How to make SUBST mapping persistent across reboots?), but it requires 3rd party software or registry changes.
    – DavidPostill
    Mar 4, 2016 at 11:34
  • Yes, but could alternatively mount it in a startup script (if that is not mentioned on that page)..
    – paradroid
    Mar 4, 2016 at 11:35
  • Ah, and there is also net use /persistent. Not used that in years!
    – paradroid
    Mar 4, 2016 at 11:38
  • 1
    @DavidPostill The ~/documents needs to be in double quotes like this: cd "~/documents", otherwise it won't be expanded properly (for...reasons). The edit is too short for me to make.
    – SBI
    Mar 4, 2016 at 12:26
12

Solution 5: Doskey

Not sure if you've been around since the dos days.. However, it's possible to overwrite command behavior using doskey macros. It's quite fun actually and doesnt require you to install any 3rd party software.

Here's a good example:

doskey cd=if "$1" equ "~" ( cd /d %userprofile%\Documents ) ELSE ( cd $* )

And a winning screenshot to go with it.

enter image description here

5
  • 2
    You probably want to add a /d to the cd %userprofile%\Documents so it works even when on other drives.
    – Ben N
    Mar 4, 2016 at 17:30
  • There is another problems with this solution: cd "WebCam Media" returns Media" ) was unexpected at this time..
    – DavidPostill
    Mar 4, 2016 at 18:39
  • The command is called doskey.This shows Windows still uses the DOS command prompt
    – Suici Doga
    Mar 5, 2016 at 3:04
  • 2
    @SuiciDoga Sorry, that's not correct. The command prompt just has a lot of compatibility features to make old batch files still run. cmd.exe is very much a Windows program, and is even 64-bit on 64-bit systems.
    – Ben N
    Mar 5, 2016 at 21:54
  • Note even though folder completion doesn't work with it due to double quotes. It will work with wildcards without double quotes. Also thanks @BenN Mar 6, 2016 at 2:32
8

%userprofile% works to get to the user's profile folder - this way you do not have to specify the drive letter.

i.e. instead of using cd C:\%HOMEPATH%\Documents you can just use cd %USERPROFILE%\Documents

3
  • That doesn't work if you are currently on another drive.
    – DavidPostill
    Mar 4, 2016 at 11:37
  • 2
    Which is easily fixed by using cd /d "%USERPROFILE%\Documents", of course.
    – Luaan
    Mar 4, 2016 at 12:44
  • This should be main answer
    – Andrew
    Mar 22, 2021 at 18:51
4

You can use %HOMEPATH%. It will take you to your home directory, just like the tilde does in linux. So to get to your desired location, the command is:

cd C:\%HOMEPATH%\Documents\
4
  • I suppose using %HOMEPATH% instead of %USERPROFILE% could be a good idea with domain accounts using Folder Redirection.
    – paradroid
    Mar 4, 2016 at 11:34
  • That doesn't work if you are currently on another drive
    – DavidPostill
    Mar 4, 2016 at 11:37
  • 1
    @DavidPostill cd /d ... ...
    – cat
    Mar 4, 2016 at 14:45
  • cd "..\Documents and Settings" does not run
    – Josem
    Apr 24, 2020 at 14:28

Not the answer you're looking for? Browse other questions tagged .