![]() |
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-08-08 18:19 |
47,811 topics / 349,895 posts / today 0 new / 48,253 members |
| DOS批处理 & 脚本技术(批处理室) » How to replace the specified path in the reg file with the current path? The path should be double slashes |
| Printable Version 2,509 / 24 |
| Floor1 pzppzp | Posted 2008-05-20 12:37 |
| 初级用户 Posts 52 Credits 110 | |
|
How to replace the specified content in the reg file with the current path? The path should be double slashes. For example, the content of a reg file is as follows:
[HKEY_CLASSES_ROOT\ProtelPCBFile\Shell\Open] [HKEY_CLASSES_ROOT\ProtelPCBFile\Shell\Open\Command] @="C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe %1" [HKEY_CLASSES_ROOT\ProtelSchematicFile] [HKEY_CLASSES_ROOT\ProtelSchematicFile\DefaultIcon] @="C:\\Program Files\\Design Explorer 99 SE\\System\\Advsch.dll,0" [HKEY_CLASSES_ROOT\ProtelSchematicFile\Shell] Need to replace "C:\\Program Files\\Design Explorer 99 SE\\" in it with the current directory, and the path should be double slashes. Please ask the expert for guidance. |
|
| Floor2 huahua0919 | Posted 2008-05-20 13:26 |
| 银牌会员 Posts 780 Credits 1,608 | |
|
a.reg
|
|
| Floor3 HAT | Posted 2008-05-20 13:32 |
| 版主 Posts 5,017 Credits 9,023 | |
|
change.exe http://upload.cn-dos.net/img/427.zip |
|
| Floor4 pzppzp | Posted 2008-05-20 13:48 |
| 初级用户 Posts 52 Credits 110 | |
|
I put the CMD file and the a.reg file in the same directory. Neither of the two can be replaced.
|
|
| Floor5 huahua0919 | Posted 2008-05-20 13:54 |
| 银牌会员 Posts 780 Credits 1,608 | |
|
```
@echo off&&setlocal enabledelayedexpansion set n=0 set path0=%~dp0 set path1=%path0:\=\\% set path2=C:\\Program Files\\Design Explorer 99 SE\\ for /f "delims=" %%i in ('type a.reg') do ( set x=%%i set t=!x:%path2%=%path1%! if !n! equ 1 (echo. >>b.txt) if !n! equ 3 (echo. >>b.txt) if !n! equ 4 (echo. >>b.txt) if !n! equ 6 (echo. >>b.txt) echo !t! >>b.txt set/a n+=1 ) pause ``` Add a pause to see the replacement [ Last edited by huahua0919 on 2008-5-20 at 03:53 PM ] |
|
| Floor6 HAT | Posted 2008-05-20 14:48 |
| 版主 Posts 5,017 Credits 9,023 | |
|
If you want to use the code on the 3rd floor, make sure to put change.exe in the same directory.
|
|
| Floor7 pzppzp | Posted 2008-05-20 15:44 |
| 初级用户 Posts 52 Credits 110 | |
|
But how can I save it after replacement, or save it as B.REG? I tried all the above and couldn't save it.
|
|
| Floor8 huahua0919 | Posted 2008-05-20 15:53 |
| 银牌会员 Posts 780 Credits 1,608 | |
|
It's been modified. Saving is just redirecting, right?
|
|
| Floor9 pzppzp | Posted 2008-05-20 16:01 |
| 初级用户 Posts 52 Credits 110 | |
|
But it will add a space at the end of each line. Also, some blank lines are deleted and some places have blank lines added, which feels a bit messy.
[HKEY_CLASSES_ROOT\.ddb] @="ProtelDesignFile" [HKEY_CLASSES_ROOT\.pcb] @="ProtelPCBFile" [HKEY_CLASSES_ROOT\.sch] @="ProtelSchematicFile" [HKEY_CLASSES_ROOT\ProtelDesignFile] [HKEY_CLASSES_ROOT\ProtelDesignFile\DefaultIcon] @="D:\\dfgdf aesfa\\System\\SmartDoc.ico" [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell] [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell\Open] [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell\Open\Command] @="\"D:\\dfgdf aesfa\\Client99SE.exe\" \"%1\"" The source file is below [HKEY_CLASSES_ROOT\.ddb] @="ProtelDesignFile" [HKEY_CLASSES_ROOT\.pcb] @="ProtelPCBFile" [HKEY_CLASSES_ROOT\.sch] @="ProtelSchematicFile" [HKEY_CLASSES_ROOT\ProtelDesignFile] [HKEY_CLASSES_ROOT\ProtelDesignFile\DefaultIcon] @="C:\\Program Files\\Design Explorer 99 SE\\System\\SmartDoc.ico" [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell] [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell\Open] [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell\Open\Command] @="\"C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe\" \"%1\"" |
|
| Floor10 bat-zw | Posted 2008-05-20 16:10 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Using findstr /n can avoid the occurrence of such confusion.
|
|
| Floor11 pzppzp | Posted 2008-05-20 16:12 |
| 初级用户 Posts 52 Credits 110 | |
|
Specifically, how to do it? I'll send the entire original text.
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.ddb] @="ProtelDesignFile" [HKEY_CLASSES_ROOT\.pcb] @="ProtelPCBFile" [HKEY_CLASSES_ROOT\.sch] @="ProtelSchematicFile" [HKEY_CLASSES_ROOT\ProtelDesignFile] [HKEY_CLASSES_ROOT\ProtelDesignFile\DefaultIcon] @="C:\\Program Files\\Design Explorer 99 SE\\System\\SmartDoc.ico" [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell] [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell\Open] [HKEY_CLASSES_ROOT\ProtelDesignFile\Shell\Open\Command] @="\"C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe\" \"%1\"" [HKEY_CLASSES_ROOT\ProtelPCBFile] [HKEY_CLASSES_ROOT\ProtelPCBFile\DefaultIcon] @="C:\\Program Files\\Design Explorer 99 SE\\System\\AdvPCB.dll,0" [HKEY_CLASSES_ROOT\ProtelPCBFile\Shell] [HKEY_CLASSES_ROOT\ProtelPCBFile\Shell\Open] [HKEY_CLASSES_ROOT\ProtelPCBFile\Shell\Open\Command] @="C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe %1" [HKEY_CLASSES_ROOT\ProtelSchematicFile] [HKEY_CLASSES_ROOT\ProtelSchematicFile\DefaultIcon] @="C:\\Program Files\\Design Explorer 99 SE\\System\\Advsch.dll,0" [HKEY_CLASSES_ROOT\ProtelSchematicFile\Shell] [HKEY_CLASSES_ROOT\ProtelSchematicFile\Shell\Open] [HKEY_CLASSES_ROOT\ProtelSchematicFile\Shell\Open\Command] @="C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe %1" |
|
| Floor12 bat-zw | Posted 2008-05-20 18:21 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Finally have time to reply:
[ Last edited by zw19750516 on 2008-5-20 at 06:49 PM ] |
|
| Floor13 不得不爱 | Posted 2008-05-20 18:56 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
@echo off
setlocal enabledelayedexpansion set path0=%~dp0 set path0=%path0:\=\\% set path1=C:\\Program Files\\Design Explorer 99 SE\\ for /f "delims=: tokens=1,*" %%a in ('findstr/n /v "+" a.reg') do ( if %%b.==. (echo.>>b.txt) ELSE ( set x=%%b set y=!x:%path1%=%path0%! echo !y!>>b.txt ) ) pause del a.reg ren b.txt a.reg |
|
| Floor14 metoo | Posted 2008-05-20 19:19 |
| 初级用户 Posts 93 Credits 195 | |
|
For needs with relatively large text replacement, you can learn Perl...
|
|
| Floor15 bat-zw | Posted 2008-05-20 20:11 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Extend cordial greetings to the super moderator of Sichuan, Bu De Bu Ai, and at the same time bless all the member brothers in Sichuan!
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |