Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I want to save %USERPROFILE% as a string read from regedit to a text file,but the cmd changes to "C:\Users\Administrator",does anybody know how to fix it?
What I want is saves like this :
"%USERPROFILE%\AppData\Local\Microsoft" in a.txt
"C:\Users\Administrator\AppData\Local\Microsoft" in a.txt
The Code:
echo %USERPROFILE%\\AppData\\Local\\Microsoft >> c:\a.txt
–
–
You double up the percents to prevent the expansion:
Echo="%%LocalAppData%%\Microsoft">a.txt
Also, notice the changed environment variable, which defines the location you were looking for.
–
–
Update Solution
Finally,I find a solution myself,thanks for all kindly help,the codes here:
Set _a=%
Set _b=USERPROFILE
Echo %_a%%_b%%_a%\\AppData\\Local\\Microsoft >> c:\a.txt
There will be works correctly in any machine,hope this can help someone who needed it like me.
In general, precede an awkward character like &<>
etc., with a caret ^
to use echo
to show it.
Naturally, %
is the exception. You need to escape %
with %
thus : %%
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.