@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