20

If I try to create files in the command prompt using the commands

mkdir C:\Users\Tristan\AppData\Roaming\modinstaller\recovery
mkdir C:\Users\Tristan\AppData\Roaming\modinstaller\mods

my computer will create the files without problems.

However, if I use the commands

mkdir C:\Users\%USERPROFILE%\AppData\Roaming\modinstaller\recovery
mkdir C:\Users\%USERPROFILE%\AppData\Roaming\modinstaller\mods

the command prompt responds with

The filename, directory name, or volume label syntax is incorrect.

How do I fix this?

Dennis
  • 48,917
  • 12
  • 130
  • 149
user210720
  • 301
  • 1
  • 2
  • 3

5 Answers5

33

The %UserProfile% variable is a special system-wide environment variable that is complete in and of itself.  It contains %SystemDrive%\Users\{username}

See this fantastic table that highlights the differences between variables in windows XP (NT5) and Windows Vista/7/8 (NT6).

Try

mkdir %userprofile%\AppData\Roaming\modinstaller\mods

Its value is the location of the current user's profile directory, in which is found that user's HKEY_CURRENT_USER (HKCU) registry hive (NTUSER).

G Koe
  • 4,720
  • 1
  • 21
  • 24
16

I assume you mixed up the variables %USERPROFILE% and %USERNAME%.

By default, %USERPROFILE% and C:\Users\%USERNAME% point to the same location. Since this is not guaranteed to be true, using %USERPROFILE% is a more reliable approach.

In general, when debugging a command like

mkdir C:\Users\%USERPROFILE%\AppData\Roaming\modinstaller\recovery

your first step should be to prepend echo.

The command

echo mkdir C:\Users\%USERPROFILE%\AppData\Roaming\modinstaller\recovery

would have shown you the following:

mkdir C:\Users\C:\Users\Tristan\AppData\Roaming\modinstaller\recovery

which is clearly not what you want.

You can also query the value of %USERPROFILE% by executing

set USERPROFILE

To see all currently defined environment variables, execute

set
Dennis
  • 48,917
  • 12
  • 130
  • 149
10

It actually appears the OP is looking not just for C:\Users\Someone but that user's AppData\Roaming folder. So, the quickest path there is to use

%APPDATA%

In the OP's example, he would use

mkdir %APPDATA%\modinstaller\recovery
mkdir %APPDATA%\modinstaller\mods
Speedbird186
  • 241
  • 2
  • 5
2

in PowerShell do not use

mkdir C:\Users\%USERPROFILE%\AppData\Roaming\modinstaller\recovery

use this:

mkdir $home\AppData\Roaming\modinstaller\recovery
  • Thanks! Can anyone provide any background resources about this? I'm trying to understand why PowerShell would do this. When I run `code %USERPROFILE` the VSCode will open to my home directory... what gives? – Jay Querido Jan 25 '21 at 17:10
-2

The %USERPROFILE% variable usually includes the C:\Users\AccountName so the correct usage would be

mkdir %USERPROFILE%\AppData\Roaming\modinstaller\recovery

user475349
  • 13
  • 1
  • 1
    This was already explained in both existing answers. If you like them, try to gain some reputation and [upvote them when you have 15 rep](https://superuser.com/help/privileges/vote-up). – gronostaj Jul 30 '15 at 20:19
  • 1
    Welcome to Super User! This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute. – DavidPostill Jul 30 '15 at 20:37