|
pzppzp
初级用户
 
积分 110
发帖 52
注册 2007-7-25
状态 离线
|
『楼 主』:
如何用当前路径替换reg文件里指定?路径要双斜杠
使用 LLM 解释/回答一下
如何用当前路径替换reg文件里指定内容?路径要双斜杠
比如一个reg文件内容如下:
[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]
要把里面的"C:\\Program Files\\Design Explorer 99 SE\\"换成当前目录,路径要双斜杠. 求高人指导
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:
@="C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe %1"
@="C:\\Program Files\\Design Explorer 99 SE\\System\\Advsch.dll,0"
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.
|
|
2008-5-20 12:37 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
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!
)
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!
)
|
|
2008-5-20 13:26 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@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
@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
|

 |
|
2008-5-20 13:32 |
|
|
pzppzp
初级用户
 
积分 110
发帖 52
注册 2007-7-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我把CMD文件和a.reg文件放到同一个目录下
两种都没不能替换啊
I put the CMD file and the a.reg file in the same directory. Neither of the two can be replaced.
|
|
2008-5-20 13:48 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
@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
加个pause就看到替换了
Last edited by huahua0919 on 2008-5-20 at 03:53 PM ]
```
@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 ]
|
|
2008-5-20 13:54 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
如果想用3楼的代码,请确保change.exe也放到同一个目录下。
If you want to use the code on the 3rd floor, make sure to put change.exe in the same directory.
|

 |
|
2008-5-20 14:48 |
|
|
pzppzp
初级用户
 
积分 110
发帖 52
注册 2007-7-25
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
可是要怎么才能替换后保存起来,或者另存为B.REG也行啊?
我试了上面的全部不能保存
But how can I save it after replacement, or save it as B.REG? I tried all the above and couldn't save it.
|
|
2008-5-20 15:44 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
改过了,保存不就是 重新定向吗
>>
It's been modified. Saving is just redirecting, right?
|
|
2008-5-20 15:53 |
|
|
pzppzp
初级用户
 
积分 110
发帖 52
注册 2007-7-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
但是他会在每行的后面加一个空格
而且有的空行会删除,有的地方会加空行,感觉 有点乱
[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\""
源文件在下面
[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\""
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.
@="ProtelDesignFile"
@="ProtelPCBFile"
@="ProtelSchematicFile"
@="D:\\dfgdf aesfa\\System\\SmartDoc.ico"
@="\"D:\\dfgdf aesfa\\Client99SE.exe\" \"%1\""
The source file is below
@="ProtelDesignFile"
@="ProtelPCBFile"
@="ProtelSchematicFile"
@="C:\\Program Files\\Design Explorer 99 SE\\System\\SmartDoc.ico"
@="\"C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe\" \"%1\""
|
|
2008-5-20 16:01 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
|
2008-5-20 16:10 |
|
|
pzppzp
初级用户
 
积分 110
发帖 52
注册 2007-7-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
具体要怎么弄啊,我把全部原文发来
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"
Specifically, how to do it? I'll send the entire original text.
Windows Registry Editor Version 5.00
@="ProtelDesignFile"
@="ProtelPCBFile"
@="ProtelSchematicFile"
@="C:\\Program Files\\Design Explorer 99 SE\\System\\SmartDoc.ico"
@="\"C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe\" \"%1\""
@="C:\\Program Files\\Design Explorer 99 SE\\System\\AdvPCB.dll,0"
@="C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe %1"
@="C:\\Program Files\\Design Explorer 99 SE\\System\\Advsch.dll,0"
@="C:\\Program Files\\Design Explorer 99 SE\\Client99SE.exe %1"
|
|
2008-5-20 16:12 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 12 楼』:
忙,先留个地,我会回复的:
使用 LLM 解释/回答一下
终于有时间回复了:
@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 ]
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 |
|
2008-5-20 18:21 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
@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
@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
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2008-5-20 18:56 |
|
|
metoo
初级用户
 
积分 195
发帖 93
注册 2006-10-28
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
感觉文本替换这种需求比较大的可以去学perl。。。
For needs with relatively large text replacement, you can learn Perl...
|
|
2008-5-20 19:19 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
向四川的不得不爱超级版主致之亲切的问候,同时祝福所有四川的会员兄弟!
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 |
|
2008-5-20 20:11 |
|