查找替换的bat脚本

@echo off
setlocal
rem cmd /v:on /c rep.bat
rem DPATH   : 指定目录
rem FILETYPE: 指定文件类型
rem SCONTENT: 替换前的字符串
rem DCONTENT: 替换后的字符串
rem TMPFILE : 临时文件

set DPATH=%1
set FILETYPE=*.txt
set SCONTENT=%2
set DCONTENT=%3
set TMPFILE=%random%.tmp

for /r %DPATH% %%i in (%FILETYPE%) do (
    if exist %TMPFILE% (del /f/q %TMPFILE%)
    for /f "usebackq tokens=*" %%j in ("%%i") do (
      set TMP=%%j
      echo !TMP:%SCONTENT%=%DCONTENT%!>nul 1>>%TMPFILE%
    )
    move /y %TMPFILE% "%%i"
)

endlocal

posted on 2008-08-17 23:41  Sanle  阅读(857)  评论(0编辑  收藏  举报

导航