CODE: [Copy to clipboard]
@echo off
setlocal enabledelayedexpansion
set file=
set /p file= 请输入要操作的文件名称(包括扩展名):
set "file=%file:"=%" ::[color=Red]此行不明白.是否是说将变量file中的字符"替换为空,用意何在.[/color]
for %%i in ("%file%") do set file=%%~fi ::[color=Red]SET FILE=%%~FI是什么用法,SET的帮助信息中好像没有[/color]
set replaced=
set /p replaced= 请输入即将被替换的内容:
set all=
set /p all= 请输入替换字符串:
for /f "delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!" ::[color=Red]此行读不明白,叹号和若干%如何作用[/color]
echo !str!>>"%file%"_tmp.txt
)
copy "%file%" "%file%"_bak.txt >nul 2>nul
move "%file%"_tmp.txt "%file%"
start "" "%file%"
[