批处理脚本不工作?
问题描述:
@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:"<int name=" /C:"<imgdir name=" /C:"<string name=" %1') do (
if not defined returnMap (
if %%a equ "returnMap" (
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
我身边有15000 XML文件中的一个文件夹中。
I have around 15 thousand xml files in one folder.
在code以上应该仔细检查每一个XML文件,并创建一个文本文件在列表中这样的所有信息;
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...
然而,当我运行该文件夹中的批处理脚本,输出我在output.txt中得到的是以下;
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.
帮助。
我引用了XML的片段例如从我的最后一个线程@ Batch不给所需的输出
I am referencing the xml's snippet example off my last thread @ Batch not giving desired output
答
您可能会测试:
@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 <nul SET /p "=%%c "
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