1. 程式人生 > >bat替換檔案中的字串

bat替換檔案中的字串

@echo off

set strOld=-t 1
set /a cpu=%number_of_processors%-1
set strNew=-t %cpu%
set file=%~dp0start.bat

setlocal enabledelayedexpansion

for /f "tokens=*" %%j in (%file%) do (
	set "tmp=%%j"
	if not !tmp!.==. (
	  set "tmp=!tmp:%strOld%=%strNew%!"
	  echo !tmp!>>temp.txt
	)
)
move temp.txt %file%