On my computer, the $env:temp
variable contains a tilde:
PS C:\> echo $env:temp
C:\Users\MOON~1.REN\AppData\Local\Temp
When I try to cd into the directory that $env:temp
points to,the following error:
PS C:\> cd $env:temp
cd : An object at the specified path C:\Users\MOON~1.REN does not exist.
Is there a possibility to force PowerShell to expand the short name of the temp directory to its full name?
Is something fishy going on?
It was pointed out that maybe something fishy is going on. This seems indeed to be the case. In cmd.exe:
C:\>echo %username%
Rene.Nyffenegger
C:\>echo %userprofile%
C:\Users\MOON.Rene
C:\>echo %temp%
C:\Users\MOON~1.REN\AppData\Local\Temp
C:\>cd %temp%
C:\Users\MOON~1.REN\AppData\Local\Temp>echo %date% > iWasHere
C:\Users\MOON~1.REN\AppData\Local\Temp>cd Users\MOON.Rene\AppData\Local\Temp
C:\Users\MOON.Rene\AppData\Local\Temp>type iWasHere
Fri 10/25/2019
The interesting thing is: if in cmd.exe, I can cd to C:\Users\MOON~1.Ren
but I can't do that in PowerShell:
C:\> cd C:\Users\MOON~1.Ren
C:\Users\MOON~1.Ren
PS C:\> cd C:\Users\MOON~1.Ren
cd : An object at the specified path C:\Users\MOON~1.Ren does not exist.
So, I really don't know what's going on here.
cd %TEMP%
will that work? if neither, then your TEMP variable is incorrect. – LPChip Oct 25 '19 at 14:48cd %temp%
takes me toC:\Users\MOON~1.REN\AppData\Local\Temp
– René Nyffenegger Oct 25 '19 at 17:02