修改一下6楼的代码,使得批处理可以放在任意位置,但是要处理的目录除外(可以放在要处理目录的子目录下),并且,生成的结果保存在批处理文件当前目录下:- @echo off
- set t=%time%
- set "olddir=%cd%"
- cd /d f:\zhubi
- (
- set /p=名称 日期<nul
- for %%i in ( *.txt) do set /p =%%~ni<nul
- echo.
- for /f "tokens=1,2" %%i in (委买1.txt) do (
- echo 正在处理 %%i>con
- set /p=%%i %%j<nul
- for /f "tokens=3" %%x in ('findstr "%%i" *.txt') do set /p=%%x<nul
- echo.
- )
- echo.
- )>"%olddir%\result.txt"
- start "" "%olddir%\result.txt"
- cls
- echo 处理完毕
- echo %t%
- echo %time%
- pause
复制代码 再来一个略为提高速度的代码,但是需要生成临时文件,该代码的思路是先把所有文本合并到一个临时文件中,然后读取该临时文件的内容,从而避免读取多个文件,使得速度略有提升:- @echo off
- set "olddir=%cd%"
- cd /d f:\zhubi
- set t=%time%
- cd.>"%olddir%\tmp.txt"
- for %%i in (*.txt) do (
- call set str1=%%str1%%+%%i
- call set str2=%%str2%% %%~ni
- )
- copy %str1:~1% "%olddir%\tmp.txt"
- echo 名称 日期 %str2%>"%olddir%\result.txt"
- cls
- (for /f "tokens=1,2" %%i in (委买1.txt) do (
- echo 正在处理 %%i>con
- set /p=%%i %%j<nul
- for /f "tokens=3" %%x in ('findstr /ib "%%i" "%olddir%\tmp.txt"') do (
- set /p=%%x<nul
- )
- echo.
- ))>>"%olddir%\result.txt"
- start "" "%olddir%\result.txt"
- cls
- echo 处理完毕
- echo %t%
- echo %time%
- pause
复制代码
|