端口替换.bat
@echo off Setlocal enabledelayedexpansion SET FIND_DIR=%~dp0 set st=7506 ::把替换字符串赋值给dt,这里举例是st->dt set dt=4506 ::循环bat文件只取文件名将文件名设置到s变量上 for /f "delims=*" %%i in ('dir /a-d /b /on %FIND_DIR%\*.bat') do ( set s=%%i if not "!s!" == "端口替换.bat" ( ::查找文件是是否在要替换的内容 find /i "%st%" %FIND_DIR%\!s!>nul&& set existFile=!s! || set existFile= :: 判断是否上一查询语句是否查询到 if not "!existFile!" == "" ( echo 修改文件!FIND_DIR!\!s! ( for /f "tokens=*" %%a in (!FIND_DIR!\!s!) do ( set scontent=%%a set scontent=!scontent:%st%=%dt%! echo !scontent! ) )>%FIND_DIR%temp1126.txt move /y %FIND_DIR%temp1126.txt "!FIND_DIR!\!s!" ) ) ) :end pause