I\'m trying to insert 800 unique
elements into an existing set of 800 XML files. I generated 800 documents
This problem have an interesting aspect, so I used it to test a different method to process files.
@echo off
setlocal EnableDelayedExpansion
rem Process all .xml files in current directory
for %%a in (*.xml) do (
rem Locate the line numbers where "CHANGETIME" and "/ENTRIES" appears
set "insertLine="
for /F "delims=:" %%b in ('findstr /N "CHANGETIME /ENTRIES" "%%a"') do (
if not defined insertLine (
set "insertLine=%%b"
) else (
set "lastLine=%%b"
)
)
rem Block used to read-input-file/create-output-file
< "%%a" (
rem Read the first line from input file
set /P "line="
rem Copy lines up to the insertion point
for /L %%i in (1,1,!insertLine!) do set /P "line=!line!" & echo/
rem Insert the corresponding REMARK file
type "RemarksFolder\%%a"
rem Copy the rest of lines
set /A insertLine+=1
for /L %%i in (!insertLine!,1,!lastLine!) do set /P "line=!line!" & echo/
) > "output.tmp"
rem Block-end
rem Replace input file with created output file
move /Y "output.tmp" "%%a" > NUL
)
This program should run faster than other methods that compare line by line; however, it has the disadvantage that leading spaces are removed from all lines. Although additional code may be inserted in order to fix this point, doing that will slow down the process...