Java程序员不会批处理脚本,批处理脚本不工作?

@echo off

setlocal EnableDelayedExpansion

(for %%z in (*.xml) do call :processFile "%%z") >output.txt

goto :EOF

:processFile

set "returnMap="

set "portal="

set /a i=0

for /F "tokens=3,5 delims==> " %%a in ('findstr /C:"

set "returnMap=[%%~b]"

)

) else (

if not defined portal (

if %%a equ "portal" set portal=true&SET /a i+=1&SET "line="

) else (

FOR %%w IN (pn pt x y tm) DO IF %%a equ "%%w" SET "line=!line! %%~b"

IF %%a equ "tn" SET "line[!i!]=!line:~1!"&SET /a i+=1&SET "line="

)

)

)

SET /a i-=1

ECHO %returnmap%

ECHO(total=%i%

FOR /l %%a IN (1,1,%i%) DO ECHO !line[%%a]!

GOTO :EOF

I have around 15 thousand xml files in one folder.

The code above is supposed to go through each xml file, and create one text file with all information in a list as such;

[10000]

total=4

sp 0 -389 183 999999999

sp 0 -416 185 999999999

sp 0 -450 183 999999999

out00 2 1080 541 20000

[3234435]

total=6

...etc...

However, when i run the batch script inside the folder, the output I get in the output.txt is the following;

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

total=-1

ECHO is off.

help.

I am referencing the xml's snippet example off my last thread @ Batch not giving desired output

解决方案

you might test this:

@ECHO OFF &SETLOCAL enableDelayedExpansion

SET "FName=file.xml"

SET "Portal="

SET "Imgdir="

SET /a xcnt=0, ycnt=0, zcnt=-1

FOR /f "tokens=2delims=<>" %%a IN ('findstr /i /c:"name=\"portal\"" /c:"name=\"pn\"" /c:"name=\"pt\"" /c:"name=\"x\"" /c:"name=\"y\"" /c:"name=\"tm\"" /c:"imgdir" /c:"returnMap" "%FName%"') DO (

FOR /f tokens^=1-2^,4delims^=^" %%b IN ("%%~a") DO (

IF /i "%%~c"=="returnMap" ECHO([%%~d]

IF DEFINED Portal (

IF DEFINED Imgdir IF NOT "%%~c"=="" SET "val.!xcnt!.!ycnt!=%%~d"&SET /a ycnt+=1

IF /i "%%~b"=="/imgdir" (

IF NOT DEFINED Imgdir (

SET "Portal="

) ELSE (

SET "Imgdir="

SET /a xcnt+=1, ycnt=0, zcnt+=1

)

)

IF /i "%%~b"=="imgdir name=" SET "Imgdir=7"

)

IF /i "%%~c"=="portal" SET "Portal=7"

)

)

ECHO(total=%xcnt%

FOR /l %%a IN (0, 1, %zcnt%) DO (

FOR /f "tokens=1*delims==" %%b IN ('SET val.%%a') DO

ECHO(

)

output is:

[10000]

total=4

sp 0 -389 183 999999999

sp 0 -416 185 999999999

sp 0 -450 183 999999999

out00 2 1080 541 20000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值