标题: [文本处理] 求助,如何用批处理替换文本中内容 [打印本页]
作者: yg8547 时间: 2023-10-11 22:57 标题: 求助,如何用批处理替换文本中内容
本帖最后由 yg8547 于 2023-10-11 23:02 编辑
假设有一个文件在C盘根目录下文件名为复制代码
,文件部分内容如下;需将里面内容复制代码
替换为复制代码
,如何用批处理来替换呢?- [Text Setting]
- TextPath=D:\Conductor90\S_Data\Report
-
- [HTML Setting]
- HTMLPath=D:\Conductor90\S_Data\Report\Html
- ;没有IIS
- URLPath=file://D:\Conductor90\S_Data\Report\Html
- ;有IIS
- ;URLPath= http://127.0.0.1/Html
-
- [Batch Setting]
- BatchPath=D:\Conductor90\S_Data\Batch_Log
- ;未装 IIS
- URLPath=file://D:\Conductor90\S_Data\Batch_Log
- ;己装 IIS
- ;URLPath= http://127.0.0.1/Batch_Log
- C:\Conductor666\
- [Trans Setting]
- TransPath=D:\Conductor90\S_Data\Trans_Log
- ;未装 IIS
- URLPath=file://D:\Conductor90\S_Data\Trans_Log
- ;己装 IIS
- ;URLPath= http://127.0.0.1/Trans_Log
复制代码
最终结果如下所示- [Text Setting]
- TextPath=C:\Conductor666\S_Data\Report
-
- [HTML Setting]
- HTMLPath=C:\Conductor666\S_Data\Report\Html
- ;没有IIS
- URLPath=file://C:\Conductor666\S_Data\Report\Html
- ;有IIS
- ;URLPath= http://127.0.0.1/Html
-
- [Batch Setting]
- BatchPath=C:\Conductor666\S_Data\Batch_Log
- ;未装 IIS
- URLPath=file://C:\Conductor666\S_Data\Batch_Log
- ;己装 IIS
- ;URLPath= http://127.0.0.1/Batch_Log
- C:\Conductor666\
- [Trans Setting]
- TransPath=C:\Conductor666\S_Data\Trans_Log
- ;未装 IIS
- URLPath=file://C:\Conductor666\S_Data\Trans_Log
- ;己装 IIS
- ;URLPath= http://127.0.0.1/Trans_Log
复制代码
作者: Nsqs 时间: 2023-10-11 23:47
- #PowerShell
- (gc '你的文件').Replace('D:\Conductor90\','C:\Conductor666\')
复制代码
作者: 77七 时间: 2023-10-12 01:09
- @fltmc>nul||mshta vbscript:CreateObject("Shell.Application").ShellExecute("%~dpnx0","%*",,"runas",1)(window.close)&&exit
- @echo off
- cd /d "%~dp0"
- (for /f "useback delims=" %%a in (`find /n /v "" ^<"c:\ConductorS.INI"`) do (
- set str=%%a
- setlocal enabledelayedexpansion
- set "str=!str:D:\Conductor90=C:\Conductor666!"
- echo=!str:*]=!
- endlocal
- ))>$
- copy $ "c:\ConductorS.INI"
- del $
- pause
复制代码
作者: yg8547 时间: 2023-10-12 11:24
感谢,我尝试另一种方法来解决了(由于 客户端有的是 win7 powershell用不了),以下是我的解决方案 (思路大概就是在文件中将路径替换为环境变量,然后通过脚本添加环境变量,将安装路径从注册表中提取出来作为环境变量添加),再次感谢各位!!!- @echo off
- MODE con: COLS=20 LINES=20
- rem 自动提权以管理员方式运行
- >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
- if '%errorlevel%' EQU '5' (
- goto UACPrompt
- ) else ( goto gotAdmin )
- :UACPrompt
- echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
- echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
- "%temp%\getadmin.vbs"
- exit /B
- :gotAdmin
- if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
- pushd "%CD%"
- CD /D "%~dp0"
-
-
- set reg1=reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\DSC\Conductor" /v ClientPath
- for /f "delims=" %%i in ('%reg1%') do set install_lj=%%i
- ::echo %install_lj%
- set testc=%install_lj:~28%
- echo %testc%
- ::%testc%
-
- setx YIFEIERP "%testc%" /M >nul
-
- copy /y "\\172.18.18.123\share\git\ConductorC.INI" "%testc%"
- copy /y "\\172.18.18.123\share\git\ConductorS.INI" "%testc%"
-
- %testc%\C_Dsbin\MainMenuEx.exe
-
- exit /b
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |