本帖最后由 nnszuo 于 2014-10-31 11:14 编辑
你应该根据最后一行内容做判断,空行直接被过滤了你那个判断没有意义
空格的问题.你把批处理中没必要的空格删除,文件路径加引号就可以了
这是修改后的内容- @echo on
- del d:\打印机1.txt d:\打印机2.txt d:\打印机3.txt d:\打印机4.txt d:\打印机5.txt
-
- if exist d:\temp.txt (echo 列表存在) else (goto eof)
- for /f "delims=" %%a in ('type d:\temp.txt^|findstr /I "打印机IP="') do (echo %%a>>d:\打印
-
- 机1.txt&&goto gname1 )
- :gname1
- for /f "delims=" %%a in ('type d:\temp.txt^|findstr "打印机名称="') do (echo %%a>>d:\打印机
-
- 1.txt%&&goto gmodel1)
- :gmodel1
- for /f "delims=" %%a in ('type d:\temp.txt^|findstr "打印机型号="') do (echo %%a>>d:\打印
-
- 机1.txt&&goto ginf1)
- :ginf1
- for /f "delims=" %%a in ('type d:\temp.txt^|findstr "打印机INF位置="') do (echo %%a>>d:\打
-
- 印机1.txt&&goto p)
-
- :p
- setlocal enabledelayedexpansion
- set scount=0
- echo on
- :P1
- set /a scount=%scount%+1
- set /a fcount=%scount%+1
- set pf=打印机%fcount%.txt
- echo %pf%
-
- :gip
- for /f "skip=%scount% delims=" %%a in ('type d:\temp.txt^|findstr /I "打印机IP=" ') do (echo
-
- %%a>>"d:\%pf%"&&goto gname)
- :gname
- for /f "skip=%scount% delims=" %%a in ('type d:\temp.txt^|findstr "打印机名称="') do (echo
-
- %%a>>"d:\%pf%"&&goto gmodel)
- :gmodel
- for /f "skip=%scount% delims=" %%a in ('type d:\temp.txt^|findstr "打印机型号="') do (echo
-
- %%a>>"d:\%pf%"&&goto ginf)
- :ginf
- for /f "skip=%scount% delims=" %%a in ('type d:\temp.txt^|findstr "打印机INF位置="') do
-
- (echo %%a>>"d:\%pf%"&&goto :p1)
复制代码 我另外做了个批处理- @echo off
- setlocal enabledelayedexpansion
- set a=0
- set m=d:\打印机
- for /f "skip=1 delims=*" %%a in (d:\temp.txt) do (
- set "k=%%a"
- if "!k:~0,5!"=="打印机IP" (
- set /a a+=1
- echo !k!>"!m!!a!.txt"
- ) else (
- echo !k!>>"!m!!a!.txt"
- )
- )
- exit
复制代码
|