![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-02 02:53 |
47,813 topics / 349,918 posts / today 0 new / 48,279 members |
| DOS批处理 & 脚本技术(批处理室) » Using a batch file to get the current username, then replace text in a file? |
| Printable Version 1,538 / 11 |
| Floor1 ygqiang | Posted 2010-04-17 07:30 |
| 新手上路 Posts 13 Credits 13 | |
|
Question: how can I use a DOS batch file to get the current username of the XP system, and then replace administrator in MirrorDir.ini?
The commands I know so far are: echo %username% display the current username echo %username%>a.txt append the displayed result to a.txt But how can I use a batch file to replace administrator in MirrorDir.ini with the current XP system username? Requirement: as soon as the batch file is run, it should immediately modify MirrorDir.ini. I don't want to use other software to do it, many thanks. The contents of MirrorDir.ini are as follows: LastTask=0 MainDir=C:\Documents and Settings\Administrator\Desktop ImageDir=d:\0beifen MainDirHistory=C:\Documents and Settings\Administrator\Desktop ImageDirHistory=d:\0beifen Excludes= StartupRun=1 DeleteOthers=1 [ Last edited by ygqiang on 2010-4-17 at 07:41 ] |
|
| Floor2 ygqiang | Posted 2010-04-17 07:40 |
| 新手上路 Posts 13 Credits 13 | |
| Floor3 ygqiang | Posted 2010-04-17 07:41 |
| 新手上路 Posts 13 Credits 13 | |
|
The main issue is:
StartupRun= DeleteOthers= In these 2 places, the 1 after them was not added. It seems this echo command can't add the number 1 into the file? [ Last edited by ygqiang on 2010-4-17 at 07:45 ] |
|
| Floor4 ygqiang | Posted 2010-04-17 07:46 |
| 新手上路 Posts 13 Credits 13 | |
|
Also, the method I'm using is a bit complicated.
Isn't there any other simpler method? |
|
| Floor5 ygqiang | Posted 2010-04-17 15:58 |
| 新手上路 Posts 13 Credits 13 | |
|
Everyone, is there no solution?
Many thanks |
|
| Floor6 Hanyeguxing | Posted 2010-04-17 16:15 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
| Floor7 Hanyeguxing | Posted 2010-04-17 16:20 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
Or
Or directly use third-party commands such as sed or fr, for example [ Last edited by Hanyeguxing on 2010-4-17 at 16:25 ] |
|
| Floor8 ygqiang | Posted 2010-04-17 21:12 |
| 新手上路 Posts 13 Credits 13 | |
|
Many thanks to the poster above.
I've already found a solution for my method. echo [CommonSetting]>MirrorDir.ini echo LastTask=0>>MirrorDir.ini echo [新任务1]>>MirrorDir.ini echo MainDir=%userprofile%\桌面>>MirrorDir.ini echo ImageDir=d:\0beifen>>MirrorDir.ini echo MainDirHistory=%userprofile%\桌面>>MirrorDir.ini echo ImageDirHistory=d:\0beifen>>MirrorDir.ini echo Excludes=>>MirrorDir.ini echo StartupRun=1 1>>MirrorDir.ini echo DeleteOthers=1 1>>MirrorDir.ini |
|
| Floor9 Hanyeguxing | Posted 2010-04-17 21:47 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
echo DeleteOthers=1 1>>MirrorDir.ini
write it as >>MirrorDir.ini echo DeleteOthers=1 |
|
| Floor10 ygqiang | Posted 2010-04-17 21:57 |
| 新手上路 Posts 13 Credits 13 | |
|
Many thanks to the poster above.
I tried it. echo DeleteOthers=1 1>>MirrorDir.ini written as >>MirrorDir.ini echo DeleteOthers=1 These two actually have the same effect in actual use. No need to modify it. |
|
| Floor11 ygqiang | Posted 2010-04-17 21:58 |
| 新手上路 Posts 13 Credits 13 | |
|
This is the software I ultimately want: timed backup of desktop files
|
|
| Floor12 Hanyeguxing | Posted 2010-04-18 00:48 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
1, when written as echo.%var%>>a.txt, the last character in %var% must not be a digit
2, so adding a space like echo.%var% >>a.txt solves it, but this will cause an extra space at the end of each line 3, >>a.txt echo.%var% means you don't need to worry whether the last character of %var% is a digit, and there won't be an extra space at the end of the line either 4, your echo.%var% 1>>a.txt is actually just echo.%var% >>a.txt |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |