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

DavidPostill
  • 153,128
  • 77
  • 353
  • 394
User1291
  • 517
  • 3
  • 7
  • 22
  • 6
    Possible duplicate of [Is there a shortcut command in Windows command prompt to get to the current users home directory like there is in Linux?](http://superuser.com/questions/168714/is-there-a-shortcut-command-in-windows-command-prompt-to-get-to-the-current-user), or of [cd (change directory) to my home directory on Windows](http://superuser.com/questions/347727/cd-change-directory-to-my-home-directory-on-windows) – Hastur Mar 04 '16 at 11:35
  • 2
    @Hastur The dupes don't address the "Documents" part of the question. – DavidPostill Mar 04 '16 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 04 '16 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 04 '16 at 12:09
  • @DavidPostill You can post in the other one too (55k view in 5 years): I can state it's a good audience that deserves a complete more answer. ;-) – Hastur Mar 04 '16 at 12:10
  • 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 04 '16 at 12:14
  • @SBI Nice one. You need `cd ~/documents` for the OPs particular case. Adding to my answer. – DavidPostill Mar 04 '16 at 12:17
  • @SBI I did not know that. 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? – User1291 Mar 04 '16 at 12:21
  • @User1291 I honestly don't know, you'd have to try. The trickyness with the powershell "unix-like" commands is that they're really just aliases for Powershell commands (hence the result when you try `man cd` showing the manpage for `set-location`). So I guess you could just give it a shot. – SBI Mar 04 '16 at 12:23
  • @User1291 You can run shortcuts from powershell. See [PowerShell trick : Execute .lnk file](http://social.technet.microsoft.com/wiki/contents/articles/30018.powershell-trick-execute-lnk-file.aspx) – DavidPostill Mar 04 '16 at 13:52
  • @User1291 PowerShell is vastly superior to cmd.exe (and bash honestly but that's a different topic), so you really, *really* want to use it (particularly if you know Bash and co - there are aliases for most of its commands). If you have existing code, you can just call `cmd /c` to execute some commands in that one which works for most circumstances (if environment variables are set in the child process you'll have to make sure to transfer them back afterwards - that's ugly but there's code somewhere on SO for that too. – Voo Mar 05 '16 at 15:26

4 Answers4

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.
DavidPostill
  • 153,128
  • 77
  • 353
  • 394
  • You could also `subst` mount the directory as a volume. – paradroid Mar 04 '16 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?](http://superuser.com/q/29072)), but it requires 3rd party software or registry changes. – DavidPostill Mar 04 '16 at 11:34
  • Yes, but could alternatively mount it in a startup script (if that is not mentioned on that page).. – paradroid Mar 04 '16 at 11:35
  • Ah, and there is also `net use` /persistent. Not used that in years! – paradroid Mar 04 '16 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 04 '16 at 12:26
  • @SBI Are you sure? I just tried it without and it worked. http://i.imgur.com/JLVKYKI.png – DavidPostill Mar 04 '16 at 12:28
  • @DavidPostill Seems to be the reason, I just tried in a vm with a regular user name. It's astonishing I've never stumbled over that before. – SBI Mar 04 '16 at 12:35
  • Instead of cygwin for most purposes msys is enough. Git for windows also includes quite a few tools to make the environment more unixy, and they might be less obtrusive than cygwin – SztupY Mar 04 '16 at 13:27
  • Power shell version is just like Linux.Microsoft created PowerShell because of the command prompt was still DOS – Suici Doga Mar 05 '16 at 03:03
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

NotAdmin Dave
  • 2,867
  • 2
  • 12
  • 20
  • 2
    You probably want to add a `/d` to the `cd %userprofile%\Documents` so it works even when on other drives. – Ben N Mar 04 '16 at 17:30
  • There is another problems with this solution: `cd "WebCam Media"` returns `Media" ) was unexpected at this time.`. – DavidPostill Mar 04 '16 at 18:39
  • The command is called `doskey`.This shows Windows still uses the DOS command prompt – Suici Doga Mar 05 '16 at 03: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 05 '16 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 – NotAdmin Dave Mar 06 '16 at 02: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

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\
techraf
  • 4,852
  • 11
  • 24
  • 40
Gasp0de
  • 249
  • 2
  • 12