BAT批量操作
1.批量替换指定文件指定内容
案列:将test.txt文本中的inflie替换为outfile
@echo off
setlocal EnableDelayedExpansion
set “CurrCD=%~dp0”
set “strOld=outfile”
set “strNew=infile”
for /f %%i in (‘dir /b /s /a:-d *.txt’) do (
powershell -Command “(gc %%i) -replace ‘%strOld%’, ‘%strNew%’ | Out-File %%i”
)
替换前
infile ‘D:\wshh_luolu\RPT测试数据文件\C_6110102.rpt’
infile ‘D:\wshh_luolu\RPT测试数据文件\C_6110104.rpt’
infile ‘D:\wshh_luolu\RPT测试数据文件\C_6110105_0.rpt’
替换后
outfile ‘D:\wshh_luolu\RPT测试数据文件\C_6110102.rpt’
outfile ‘D:\wshh_luolu\RPT测试数据文件\C_6110104.rpt’
outfile ‘D:\wshh_luolu\RPT测试数据文件\C_6110105_0.rpt’