Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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\ ?

share|improve this question

marked as duplicate by Hastur, Canadian Luke, Steven, Raystafarian, fixer1234 Mar 6 at 2:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

6  
2  
@Hastur The dupes don't address the "Documents" part of the question. – DavidPostill Mar 4 at 11:58
    
@DavidPostill The title is the same(you may think to change it), the answers rely on %USERPROFILE%, %HOMEPATH% setting a variable, doing a bat file, using MinGW... as in the others. Can we do other questions about how to change into the Desktop directory and so on? I hate to close questions it's against my nature :-) – Hastur Mar 4 at 12:06
    
@Hastur Yes, I will change the title. Also my answer provides some other suggestions that aren't covered in the dupes ... – DavidPostill Mar 4 at 12:09
3  
Have you considered using powershell instead of cmd? Or doesn't that float for some other reason? Because cd ~ in powershell works just like under unix. – SBI Mar 4 at 12:14
up vote 20 down vote accepted

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.
share|improve this answer
    
You could also subst mount the directory as a volume. – paradroid Mar 4 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 at 11:34
    
Yes, but could alternatively mount it in a startup script (if that is not mentioned on that page).. – paradroid Mar 4 at 11:35
    
Ah, and there is also net use /persistent. Not used that in years! – paradroid Mar 4 at 11:38
    
@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 at 12:26

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

share|improve this answer
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 at 17:30
    
There is another problems with this solution: cd "WebCam Media" returns Media" ) was unexpected at this time.. – DavidPostill Mar 4 at 18:39
    
The command is called doskey.This shows Windows still uses the DOS command prompt – Suici Doga Mar 5 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 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 – Guitar Shoe Dave Mar 6 at 2:32

%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

share|improve this answer
    
That doesn't work if you are currently on another drive. – DavidPostill Mar 4 at 11:37
2  
Which is easily fixed by using cd /d "%USERPROFILE%\Documents", of course. – Luaan Mar 4 at 12:44

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\
share|improve this answer
    
I suppose using %HOMEPATH% instead of %USERPROFILE% could be a good idea with domain accounts using Folder Redirection. – paradroid Mar 4 at 11:34
    
That doesn't work if you are currently on another drive – DavidPostill Mar 4 at 11:37
1  
@DavidPostill cd /d ... ... – cat Mar 4 at 14:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.