[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. @echo off
  2. REM 获取bat上级路径
  3. set "bd=%cd%"
  4. cd..
  5. set "bbd=%cd%"
  6. cd %bd%
  7. set Newdisk=%bbd%
  8. set strIceBoxFilePath=d:\sec\icebox\icebox.txt
  9. REM 读取旧盘符
  10. set Olddisk=
  11. for /f "tokens=1*" %%i in ('findstr "IceBox\\" "%strIceBoxFilePath%"') do (
  12.   set Olddisk=%%j
  13. )
  14. if not defined Olddisk exit /b
  15. set "prefix=%Olddisk%\."
  16. @REM echo prefix_before=%prefix%
  17. :loop3
  18. for %%A in ("%prefix%") do (
  19.   set "prefix=%%~dpA."
  20.   if /i not "%%~nxA"=="IceBox" if not "%%~pA"=="\" (
  21.     goto loop3
  22.   )
  23. )
  24. set "prefix=%prefix:~,-1%"
  25. @REM echo prefix_after=%prefix%
  26. REM 读取IceBox_*.dat所有内容
  27. for /f "eol=! tokens=*" %%l in (%strIceBoxFilePath%) do (
  28. REM 设置变量str为每行内容
  29. setlocal EnableDelayedExpansion
  30. set str=%%l
  31. REM 如果该行有旧盘符a,则将其改为新盘符A
  32. set "str=!str:%prefix%=%Newdisk%\!"
  33. REM 把修改后的全部行存入$
  34. echo !str!>>$
  35. endlocal
  36. )
  37. REM 替换原文件
  38. move $ %strIceBoxFilePath%
  39. echo 设置完成!
复制代码
微信:flashercs
QQ:49908356

TOP

  1. findstr /ric:"creotkdat  *.*\\IceBox\\IceBox_c4.dat" %strConfigFilePath%
  2. if %errorlevel% equ 1 >>%strConfigFilePath% echo creotkdat %Newdisk%\IceBox\IceBox_c4.dat
复制代码
回复 6# HerveyHu
微信:flashercs
QQ:49908356

TOP

  1. @echo off
  2. REM 获取bat上级路径
  3. set "bd=%cd%"
  4. cd..
  5. set "bbd=%cd%"
  6. cd %bd%
  7. set Newdisk=%bbd%
  8. set strIceBoxFilePath=d:\sec\icebox\icebox.txt
  9. REM 读取旧盘符
  10. set Olddisk=
  11. for /f "tokens=1*" %%i in ('findstr "IceBox\\" "%strIceBoxFilePath%"') do (
  12.   set Olddisk=%%j
  13. )
  14. if not defined Olddisk exit /b
  15. set "prefix=%Olddisk%\."
  16. @REM echo prefix_before=%prefix%
  17. :loop3
  18. for %%A in ("%prefix%") do (
  19.   set "prefix=%%~dpA."
  20.   if /i not "%%~nxA"=="IceBox" if not "%%~pA"=="\" (
  21.     goto loop3
  22.   )
  23. )
  24. set "prefix=%prefix:~,-1%"
  25. @REM echo prefix_after=%prefix%
  26. REM 读取IceBox_*.dat所有内容
  27. for /f "eol=! tokens=*" %%l in (%strIceBoxFilePath%) do (
  28. REM 设置变量str为每行内容
  29. setlocal EnableDelayedExpansion
  30. set str=%%l
  31. REM 如果该行有旧盘符a,则将其改为新盘符A
  32. set "str=!str:%prefix%=%Newdisk%\!"
  33. REM 把修改后的全部行存入$
  34. echo !str!>>$
  35. endlocal
  36. )
  37. REM 替换原文件
  38. move $ %strIceBoxFilePath%
  39. set strConfigFilePath=d:\sec\icebox\icebox.txt
  40. findstr /ric:"creotkdat  *.*\\IceBox\\IceBox_c4.dat" %strConfigFilePath%
  41. if %errorlevel% equ 1 (
  42.   REM 未找到
  43.   >>%strConfigFilePath% echo creotkdat %Newdisk%\IceBox\IceBox_c4.dat
  44.   goto end
  45. )
  46. set reNewdisk=%Newdisk:\=\\%
  47. set reNewdisk=%reNewdisk:\.=\.%
  48. REM 找到
  49. findstr /ric:"creotkdat  *%reNewdisk%\\IceBox\\IceBox_c4.dat" %strConfigFilePath%
  50. REM 不匹配%Newdisk%
  51. 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%\""
  52. :end
  53. echo 设置完成!
复制代码
微信:flashercs
QQ:49908356

TOP

回复 11# HerveyHu


    可以,你批处理脚本能读取utf8吗?
你把批处理脚本保存为utf8-nobom编码,同时最上边修改成这样:
  1. @echo off
  2. chcp 65001
  3. REM 获取bat上级路径
复制代码
微信:flashercs
QQ:49908356

TOP

  1. if %errorlevel% equ 1 powershell -NoProfile -Command "(Get-Content -LiteralPath \"%strConfigFilePath%\" -ReadCount 0 -Encoding utf8) -replace \"(%Pathtype%\s+).*?(?=\\IceBox\\IceBox_%c%.dat)\", \"`${1}%Newdisk%\" | Set-Content -Encoding utf8 -LiteralPath \"%strConfigFilePath%\""||del /f /s /q /a "%bct%$"
复制代码
回复 14# HerveyHu
微信:flashercs
QQ:49908356

TOP

返回列表