标题: [文本处理] 批处理如何循环读取txt文件 [打印本页]
作者: 123rt 时间: 2011-12-27 14:05 标题: 批处理如何循环读取txt文件
本帖最后由 CrLf 于 2011-12-28 20:23 编辑
代码如下- for /f "delims= " %%i in (z.txt) do del %%i.bat
- for /f "delims= " %%i in (z.txt) do echo goto start>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo :start>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo a.exe %%i %%i.bat
- for /f "delims= " %%i in (z.txt) do echo if errorlevel 1 goto exit>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo if errorlevel 0 goto d>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo :d>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo (echo %%i^>^>a.txt)>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo goto exit>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo :exit>>%%i.bat
- for /f "delims= " %%i in (z.txt) do echo exit>>%%i.bat
- for /f "delims= " %%i in (z.txt) do start %%i.bat
- exit
复制代码
从z.txt中读取参数给a.exe,把成功的结果输出到a.txt中,现在问题是,z.txt中有几千行的参数,那么运行后,就会产生几千个bat,怎么能设定一次读取100个,完成后继续往下执行,知道读取全部z.txt中的参数,请各位大虾们指教!
作者: s700800900 时间: 2011-12-27 17:00
本帖最后由 CrLf 于 2011-12-28 20:24 编辑
由于你要判断a.exe的结果再输出.所以我觉得用两个批好点
第一个,实现每次100个输出,保存任意名字.- @echo off
- setlocal enabledelayedexpansion
- set n=0
-
- for /f "delims=" %%a in (z.txt) do (
- if /i "!n!" neq "100" (
- start "" "a.bat" "%%a"
- set /a n=n+1
- ) else (
- "a.exe" "%%a"
- if /i "%errorlevel%" equ "0" (
- echo %%a >> "a.txt"
- )
- set n=0
- )
- )
复制代码
第二个保存为a.bat,- @echo off
- cd /d "%~dp0"
- a.exe %1
- if /i "%errorlevel%" equ "0" (
- echo %1 >> a.txt
- )
复制代码
这种方法我没有实测过.~~估计有问题.~~哈哈,可以当做参考.~
作者: 123rt 时间: 2011-12-28 17:23
多谢指点了
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |