- @echo off
-
- REM 获取bat上级路径
-
-
- set "bd=%cd%"
- cd..
- set "bbd=%cd%"
- cd %bd%
- set Newdisk=%bbd%
-
- set strIceBoxFilePath=d:\sec\icebox\icebox.txt
- REM 读取旧盘符
- set Olddisk=
- for /f "tokens=1*" %%i in ('findstr "IceBox\\" "%strIceBoxFilePath%"') do (
- set Olddisk=%%j
- )
- if not defined Olddisk exit /b
- set "prefix=%Olddisk%\."
- @REM echo prefix_before=%prefix%
- :loop3
- for %%A in ("%prefix%") do (
- set "prefix=%%~dpA."
- if /i not "%%~nxA"=="IceBox" if not "%%~pA"=="\" (
- goto loop3
- )
- )
- set "prefix=%prefix:~,-1%"
- @REM echo prefix_after=%prefix%
- REM 读取IceBox_*.dat所有内容
- for /f "eol=! tokens=*" %%l in (%strIceBoxFilePath%) do (
-
-
- REM 设置变量str为每行内容
-
- setlocal EnableDelayedExpansion
- set str=%%l
- REM 如果该行有旧盘符a,则将其改为新盘符A
- set "str=!str:%prefix%=%Newdisk%\!"
-
-
- REM 把修改后的全部行存入$
- echo !str!>>$
- endlocal
-
- )
-
-
- REM 替换原文件
-
-
- move $ %strIceBoxFilePath%
-
- set strConfigFilePath=d:\sec\icebox\icebox.txt
- findstr /ric:"creotkdat *.*\\IceBox\\IceBox_c4.dat" %strConfigFilePath%
- if %errorlevel% equ 1 (
- REM 未找到
- >>%strConfigFilePath% echo creotkdat %Newdisk%\IceBox\IceBox_c4.dat
- goto end
- )
- set reNewdisk=%Newdisk:\=\\%
- set reNewdisk=%reNewdisk:\.=\.%
- REM 找到
- findstr /ric:"creotkdat *%reNewdisk%\\IceBox\\IceBox_c4.dat" %strConfigFilePath%
- REM 不匹配%Newdisk%
-
- if %errorlevel% equ 1 powershell -NoProfile -Command "(Get-Content -LiteralPath \"%strConfigFilePath%\" -ReadCount 0) -replace \"(creotkdat\s+).*?(?=\\IceBox\\IceBox_c4.dat)\", \"`${1}%Newdisk%\" | Set-Content -LiteralPath \"%strConfigFilePath%\""
-
- :end
- echo 设置完成!
复制代码
|