Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using various linux distributions for quite some time now and become accustomed to using the "~" key to indicate "home" when typing in paths.

Today, working in Windows 7, I found myself doing the same thing in the "File Name" field of a "File Open" dialog. I realized that I could substitute %HOMEPATH%, but this seems too long for repeated use. It's certainly fine for scripting though (IMO).

Is there an equivalent to "~" in Windows? If not, is there a way to implement "~" as the %HOMEPATH% variable? I tried creating a System variable with "~" and the OS hasn't given me any trouble with this (as far as I can tell), but it doesn't seem to work.

Any suggestions would be much appreciated!

share|improve this question
    
Within PowerShell ~ has this meaning, perhaps as a nod to Unixy conventions. –  Joey Nov 15 '12 at 6:52

4 Answers 4

no. (to all of your questions)

the way of the hackerish-crazy: use autohotkey to check any typed key for "~", check that the user really means "~" and then replace that with the full path of %USERPROFILE% / %HOMEPATH%. but in general: no.

share|improve this answer

The only thing you can do is set the variable of ~ to your home directory:

set ~=%HOMEDRIVE%%HOMEPATH%

Which if you echo out the value of the variable:

echo %~%

You will see your home directory...

But if you do this inside of the command prompt you wont be able to use it inside of Windows. If you goto control panel -> System -> Advanced System Settings (or just Advanced if on XP) click on Environment Variables and click New under System Variables and set the variable name to ~ and the Variable Value to %HOMEDRIVE%%HOMEPATH% and click ok. You should be able to "run" %~% and it will take you to your home directory. Unfourntally, you cannot access the variable without the percent signs.

share|improve this answer
    
Ok, this makes the most sense. So I tried your suggestion and am not able to get it working (in Windows 7 -- haven't tried other Windows OS). I first tried this as a system variable and it simply outputs %~% as the literal "%HOMEDRIVE%%HOMEPATH%". However, I can echo, or type into explorer %HOMEDRIVE%%HOMEPATH% and it works just fine. This is also true when using 'set' on command line. I've done some searching in Google, but haven't found anything so far. Thanks for the suggestion. –  seedofc Oct 25 '09 at 18:08
    
It works fine for me, are you putting quotes when you are setting the Variable value? If yes, then you should take them out because with quotes Windows treats anything inside the quotes as a literal. –  Nathan Adams Oct 25 '09 at 18:53
    
Hmm.. no quotes. –  seedofc Oct 25 '09 at 19:05
    
remplace "%HOMEDRIVE%%HOMEPATH%" with the real address eg. c:\users\<username>\ –  Revolter Oct 25 '09 at 19:36
    
btw, it's %USERPROFILE% .. the equivalent to $HOME –  akira Oct 26 '09 at 13:07

Perhaps this works for you too:

  1. Open Explorer and browse to the directory/folder containing your user dir.
  2. Right click and select Send to desktop as shortcut.
  3. Go to your desktop and rename that shortcut to ~.
  4. Open Explorer again on a random directory and input ~ in the address bar.
  5. It should take you to your home directory.

Not really suited for command line usage though. An alias would work here though

share|improve this answer
    
You may also try C:\>doskey ~=cd C:\Users\yourusername . Then simply type ~ . –  mr-euro Oct 25 '09 at 17:46
    
Perhaps a hardlink to the directory: fsutil hardlink create dir dir –  mr-euro Oct 25 '09 at 17:51

Download MSYS which is part of MinGW, and then set your HOME variable to whatever you want. In your MSYS shell, which is a bash shell, you will have ~ as your HOME directory. BTW: installing MSYS and MinGW is a snap with their installer and package manager.

Alternately, if you are so inclined, you can install Cygwin or KDE for Windows; either will give you a POSIX-like environment.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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