查找文件夹路径并替换注册表文件内路径
能正常运行的代码如下: | @echo off | | setlocal enabledelayedexpansion | | | | set "target=PETOOLS" | | set "regfile=1.reg" | | set "found=" | | | | rem 遍历所有分区(C到Z) | | for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( | | if exist %%d:\ ( | | echo 正在搜索 %%d 盘... | | | | for /f "delims=" %%a in ('dir /s /b /ad %%d:\%target% 2^>nul') do ( | | set "path=%%a" | | | | if not "%%~dpa"=="%%d:\" ( | | | | set "newpath=!path:\=\\!" | | set "found=!newpath!" | | goto replace | | ) | | ) | | ) | | ) | | | | :replace | | if defined found ( | | echo 替换目标路径为: %found% | | | | ( | | for /f "usebackq delims=" %%i in ("%regfile%") do ( | | set "line=%%i" | | set "line=!line:C:\\PETOOLS=%found%!" | | echo !line! | | ) | | ) > "%regfile%.tmp.reg" | | | | rem 替换原文件 | | move /y "%regfile%.tmp.reg" "%regfile%" > nul | | echo SUCCESS | | ) else ( | | echo FAILED | | ) | | | | endlocal | | pause | | | | pauseCOPY |
----------------------------------------------------------------------------------------------------------------------------------------------------
批处理通过所有分区深层子目录中搜索,查到第一个文件夹PETOOLS后中止搜索,并把注册表1.reg中原有的路径C:\\PETOOLS替换为新的路径,注意:注册表路径是双斜杠\\,,单斜杠是无法导入注册表的,路径中没有空格也没特殊字符,也不需要搜索分区根目录,只要子目录,不要用wmic 也不要用poseerhsell 批处理代码如何写?
以下是AI给出的代码:
运行没成功,显示系统没找到指定的文件,如何修改,大神帮忙看一下。 | setlocal enabledelayedexpansion | | set "target=PETOOLS" | | set "regfile=1.reg" | | set "found=" | | | | rem 遍历所有分区(C到Z) | | for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( | | if exist %%d:\ ( | | echo 正在搜索 %%d 盘... | | | | for /f "delims=" %%a in ('dir /s /b /ad %%d:\%target% 2^>nul') do ( | | set "path=%%a" | | | | if not "%%~dpa"=="%%d:\" ( | | | | set "newpath=!path:\=\\!" | | set "found=!newpath!" | | goto replace | | ) | | ) | | ) | | ) | | | | :replace | | if defined found ( | | echo :%found% | | | | (for /f "usebackq delims=" %%i in ("%regfile%") do ( | | set "line=%%i" | | set "line=!line:C:\\PETOOLS=%found%!" | | echo !line! | | )) >"%regfile%.tmp" | | | | rem 替换原文件 | | move /y "%regfile%.tmp""%regfile%">nul | | echo SUCCESS | | ) else ( | | echo FAILED | | ) | | | | endlocal | | pauseCOPY |
|