2
I have been trying to make a batch file using another batch file.
The file I want to make needs to contain %username%
in order for it to be functional in other computers as well.
Whenever I try to do it it types my actual username in the file which makes it impossible to run on other computers. Can someone please help me with my problem?
Here is what I wrote in the batch file:
Echo cd c:\Users\%username%\Documents > x.bat
But when I open x.bat it says:
Echo cd c:\Users\myname\Documents
I actually know what causes this problem but I couldn't find any way to get past it.
1To avoid instant expansion double the enclosing percent signs in the generating batch,
%%USERNAME%%
– LotPings – 2018-06-22T11:26:31.377Does the same thing apply for %random% ? – Ali Demir – 2018-06-22T11:33:18.973
Yes, enclose similarly
%%random%%
– LotPings – 2018-06-22T11:36:25.580%
is escape character in batch file. Use%%
instead of one%
. More Details. – Sandeep – 2018-06-22T11:37:53.2101@LotPings, why not expand your comment slightly as an answer, since it successfully resolves the issue. – DrMoishe Pippik – 2018-06-22T16:29:59.183