Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to resolve double percents in batch variable?

I’m getting a value from the registry which has this string of data: %USERPROFILE%\Desktop
If i manually put cd %USERPROFILE%\Desktop it’d correctly perform cd C:\Users\Name\Desktop
But when i read the data from the registry, it gives set DESKTOP = %%USERPROFILE%%\Desktop

So if i do cd %DESKTOP% (cd %%USERPROFILE%%\Desktop) it performs cd %USERPROFILE%\Desktop
Which gives the error: The system cannot find the path specified.

How can i resolve/evaluate the %%USERPROFILE%%\Desktop string data? (so %%USERPROFILE%% becomes C:\Users\Name)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Also this is how i get the data from the registry:
for /f "tokens=2*" %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop') do set DESKTOP=%%b

>Solution :

You need the CALL command to evaluate an expression a second time.

echo %desktop%
call echo %desktop%

The CALL also works with other commands like SET, but not in front of IF or FOR

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading