Can locations like appDataLocation and tempLocation have spaces in their path

C:\Users\username\AppData\Roaming
C:\Users\username\AppData\Local\Temp

I am writing an app for windows and my app will be using these two locations above quite often and to avoid any surprises I want to know for sure if Windows allow these locations to have spaces in their paths like for example:

C:\Users\user Name\AppData\Roaming
C:\Users\user Name\AppData\Local\Temp

I went through a couple of MS docs but couldn't find this specific info.


Solution 1:

They certainly could, and not only because of the user name.

In all Windows 2000/XP systems, those two directories were located at:

C:\Documents and Settings\User\Application Data
C:\Documents and Settings\User\Local Settings\Temp

(I've heard rumors that this naming was chosen deliberately, to force newly written programs to accept long file names in case "C:\Program Files" wasn't enough of a push.)

While those Windows versions are now mostly out-of-support, such paths may still linger in app configurations if the same system was directly upgraded from 2000/XP to Vista/7 and from there to Win8/10. They remain valid paths in modern versions, too, thanks to Windows creating hidden symlinks pointing the old names to new ones.

In general, a well-written program should always assume that any path might contain spaces, commas, apostrophes, and other funny things. They've been allowed in paths ever since "C:\My Documents" in Windows 95 – in 2021 they should be a baseline assumption, not a "surprise"!

Solution 2:

There are no limitation on the user-name/account-name. It may contain spaces, and the documentation doesn't see the need to mention that.

For example see the post Windows 10 - Username with whitespace and PATH, where the user name was "Miha Šušteršič".

Solution 3:

You can have spaces in the name.

Here is an example on my own machine.

Otherwise folder names should be used exactly as Windows has them (e.g. AppData does not have spaces).

User name with spaces