Batch script not working?

你。 提交于 2020-01-17 06:17:05

问题


@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

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


回答1:


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 <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


来源:https://stackoverflow.com/questions/22651038/batch-script-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!