16

The original User's Profile directory lives in a directory like C:\Users\username\AppData.

How can I refer to the current user's profile directory when using the Windows command line?

By searching I found out about %UserProfile% that perhaps refer to the current username, but it does not really work. When I tried using it, I received the error "The filename, directory name, or volume label syntax is incorrect".

Matt
  • 374
  • 3
  • 14
super
  • 161
  • 1
  • 1
  • 3
  • 2
    In what context do you get the error? `CD %USERPROFILE%` works as expected, as does `CD %LOCALAPPDATA%` and `CD %APPDATA%` – stuartd Nov 28 '13 at 13:38
  • Wjen I used C:\Users\%UserProfile%\AppData – super Dec 09 '13 at 19:24
  • 1
    Ah. That would be the issue then. C:\Users\%UserProfile%\AppData would expand to "C:\Users\C:\Users\Super\AppData"! "cd %USERPROFILE%\AppData" works as expected. – carveone Dec 11 '13 at 17:57
  • Thanks carveone...hope will be answering my needs further – super Dec 12 '13 at 18:31

2 Answers2

11

Here are some of the common system path variables on windows, but check here for a complete reference:

| Variable       | Default Value                                                                |
|----------------|------------------------------------------------------------------------------|
| %SystemDrive%  | C:                                                                           |
| %ProgramFiles% | C:\Program Files                                                             |
| %AppData%      | C:\Users\{username}\AppData\Roaming                                          |
| %LocalAppData% | C:\Users\{username}\AppData\Local                                            |
| %UserProfile%  | C:\Users\{username}                                                          |
| %UserName%     | {username}                                                                   |
| %COMPUTERNAME% | {computername}                                                               |
| %PATH%         | C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths} |

These should automatically be expanded when using the windows cmd prompt (or bash / powershell):

cd %UserProfile%

Your specific issue here seems to be using UserProfile instead of UserName. Either use cd %UserProfile% or cd C:\Users\%UserName%

Further Reading:

KyleMit
  • 5,992
  • 7
  • 46
  • 61
  • 2
    Good answer! I learned. – Hannes Schneidermayer Aug 01 '20 at 12:14
  • *Hint:* You can use `ECHO %variable%` to print its content in the console, e.g. `ECHO %UserProfile%` or you can use `SET variable` without assignment, which will also print it , e.g. `SET UserProfile`. And just typing `SET` prints *all* environment variables. – Matt Mar 30 '23 at 14:16
4

Run a command shell (start/Run, then "cmd") and type "set". This will list all the environmental variables available. Having said that, USERPROFILE is perfectly valid. There's also APPDATA and LOCALAPPDATA.

Ramhound
  • 41,734
  • 35
  • 103
  • 130
carveone
  • 327
  • 2
  • 10