China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-08 17:19
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to replace the specified path in the reg file with the current path? The path should be double slashes View 2,504 Replies 24
Original Poster Posted 2008-05-20 12:37 ·  中国 广东 深圳 电信
初级用户
★★
Credits 110
Posts 52
Joined 2007-07-25 16:12
19-year member
UID 94014
Gender Male
Status Offline
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.
Floor 2 Posted 2008-05-20 13:26 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
a.reg

@echo off&&setlocal enabledelayedexpansion
set path0=%~dp0
set path1=%path0:\=\\%
set path2=C:\\Program Files\\Design Explorer 99 SE\\
for /f "delims=" %%i in (a.reg) do (
set x=%%i
set t=!x:%path2%=%path1%!
echo !t!
)
Floor 3 Posted 2008-05-20 13:32 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
@echo off
change a.reg /from "\\" /to "\" /in "C:\\Program Files\\Design Explorer 99 SE\\"
change a.reg /from "C:\Program Files\Design Explorer 99 SE\" /to "%~dp0"
change a.reg /from "\" /to "\\" /in "%~dp0"


change.exe
http://upload.cn-dos.net/img/427.zip
Floor 4 Posted 2008-05-20 13:48 ·  中国 广东 深圳 电信
初级用户
★★
Credits 110
Posts 52
Joined 2007-07-25 16:12
19-year member
UID 94014
Gender Male
Status Offline
I put the CMD file and the a.reg file in the same directory. Neither of the two can be replaced.
Floor 5 Posted 2008-05-20 13:54 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
```
@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 ]
Floor 6 Posted 2008-05-20 14:48 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
If you want to use the code on the 3rd floor, make sure to put change.exe in the same directory.
Floor 7 Posted 2008-05-20 15:44 ·  中国 广东 深圳 福田区 电信
初级用户
★★
Credits 110
Posts 52
Joined 2007-07-25 16:12
19-year member
UID 94014
Gender Male
Status Offline
But how can I save it after replacement, or save it as B.REG? I tried all the above and couldn't save it.
Floor 8 Posted 2008-05-20 15:53 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
It's been modified. Saving is just redirecting, right?
Floor 9 Posted 2008-05-20 16:01 ·  中国 广东 深圳 福田区 电信
初级用户
★★
Credits 110
Posts 52
Joined 2007-07-25 16:12
19-year member
UID 94014
Gender Male
Status Offline
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\""
Floor 10 Posted 2008-05-20 16:10 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Using findstr /n can avoid the occurrence of such confusion.
批处理之家新域名:www.bathome.net
Floor 11 Posted 2008-05-20 16:12 ·  中国 广东 深圳 福田区 电信
初级用户
★★
Credits 110
Posts 52
Joined 2007-07-25 16:12
19-year member
UID 94014
Gender Male
Status Offline
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"
Floor 12 Posted 2008-05-20 18:21 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Finally have time to reply:
@echo off
set puth1=C:\\Program Files\\Design Explorer 99 SE\\
set puth2=%~dp0
set puth2=%puth2:\=\\%
for /f "tokens=1* delims=: " %%i in ('findstr /n ".*" a.reg') do (
set str=%%j&set /a n+=1
setlocal enabledelayedexpansion
if defined str set str=!str:%puth1%=%puth2%!
if !n! equ 1 (
echo.!str!>a.reg
) else (
echo.!str!>>a.reg
)
endlocal
)
echo 替换完成!
pause>nul


[ Last edited by zw19750516 on 2008-5-20 at 06:49 PM ]
批处理之家新域名:www.bathome.net
Floor 13 Posted 2008-05-20 18:56 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
@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
Floor 14 Posted 2008-05-20 19:19 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 195
Posts 93
Joined 2006-10-28 08:20
19-year member
UID 68626
Gender Male
Status Offline
For needs with relatively large text replacement, you can learn Perl...
Floor 15 Posted 2008-05-20 20:11 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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!
批处理之家新域名:www.bathome.net
Forum Jump: