Running %temp% goes to file in Users folder

batch filetemporary-fileswindowswindows 10

Recently, I built a .bat file to delete temporary files and ran it. The code for it is:

@ECHO OFF
color 0f
echo -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
echo (                               Delete Temporary Files                                  )
echo -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
echo This will delete temporary files from your system.
pause
echo.
echo Deleting system terporary files...
del %SystemDrive%\Windows\Temp\ /Q
echo System temporary files deleted!
echo.
echo Deleting user temporary files...
del %tmp% /Q
echo User temporary files deleted!
echo.
echo All temporary files deleted!
echo.
echo Press ENTER to finish...
set /p exit=""

It works, but now (when I go to %Temp% from File Explorer or Run box), it asks How do you want to open this file?
When I select Notepad++, it opens a file with my username, located at C:\Users\Zackary (as opposed to my user directory, C:\Users\ZACKAR~1\ ). The file reads:

Invalid number of parameters
Invalid number of parameters
Invalid number of parameters
Invalid number of parameters
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

TO CLARIFY: %tmp% and %temp% have the same values. This is taken directly from CMD.

TEMP=C:\Users\ZACKAR~1\AppData\Local\Temp
TMP=C:\Users\ZACKAR~1\AppData\Local\Temp

This problem does not happen on any other user accounts on this computer. It has happened even before I had a Black Screen of Death with cursor (which lead to replacing the hard drive). I have tried rebooting, signing out and back in again, making sure the folder exists, etc.
How do I make %temp% go back to my temporary files folder?

EDIT: I found the problem. There is a space in my non-8.3 user folder (Zackary R) That causes programs to see it as 2 parameters C:\Users\Zackary (as 1st parameter) and R\AppData\Local\Temp (as second parameter) It reads the first parameter, causing it to reroute to the file Zackary in the Users folder.

Best Answer

I fixed it - it was a lot simpler them I thought.

There was a space in my non-8.3 user folder (for example, User Name, rather then USERNA~1) that would cause programs to see it as 2 parameters C:\Users\User (as 1st parameter) and Name\AppData\Local\Temp (as second parameter). It reads the first parameter, causing it to reroute to the file User in the Users folder. Deleting the file C:\Users\User solved it (It was not important because it only contained CMD errors).

The workaround (without deleting that file) is to use %tmp% and %temp% references in quotes.

Related Question