首先: 注册表添加一个或两个 REG_DWORD 值: HKEY_LOCAL_MACHINE/Software/Microsoft/Command Processor/EnableExtensions 或 HKEY_CURRENT_USER/Software/Microsoft/Command Processor/EnableExtensions 设值为1 新建文件aaa.bat: @echo off set f=c:/aaa.txt set f2="c:/aaa.bak.txt" for /?>%f% if exist %f2% del %f2% for /f "tokens=* delims=%" %%l in (%f%) do ( set line=%%l set line=!line:FOR=F_O_R! echo !line!>>%f2% ) 执行aaa.bat 所有的FOR都被替换为F_O_R并写入aaa.bak.txt 缺点:原文件(aaa.txt)空行无法读取