日期:2014-05-17 浏览次数:21685 次
@echo off setlocal ENABLEDELAYEDEXPANSION for /f %%i in ('dir /b /a:-d *root*.txt') do ( call :replace %%i >%%i.replace del %%i ren %%i.replace %%i ) goto :eof :replace for /f "tokens=1,* delims=:" %%j in ('findstr /n ".*" %1') do ( if "%%k"=="" ( echo. ) else ( set tmpline=%%k set tmpline=!tmpline:-=/! echo !tmpline! ) ) goto :eof
------解决方案--------------------
写一个
@echo off ::把需要搜索的路径赋值给变量sp,这里举例是c:\tmp set sp=c:\tmp ::把需要查找的文件名赋值给变量cf,这里举例是root.txt set cf=root.txt ::把将被替换的字符串赋值给st,这里举例是apple set st=apple ::把替换字符串赋值给dt,这里举例是lemon set dt=lemon ::以上的这些赋值执行后,将会把C盘tmp文件夹下面包括子文件夹里的root.txt中的apple全部替换成lemon ::下面的代码将完成替换工作 for /r %sp% %%a in (%cf%) do (call :doit "%%~dpa") goto end :doit setlocal enabledelayedexpansion pushd %1 for /f "tokens=1,2* delims=:" %%i in ('findstr /n ".*" %cf%') do ( set txt=%%j if "!txt!" == "" ( echo.>>%1root.tmp ) else ( echo !txt:%st%=%dt%!>>%1root.tmp ) ) move /y root.tmp root.txt :end
------解决方案--------------------