Add additional text to existing output file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Add additional text to existing output file.

#1 Post by Matt Williamson » 29 Aug 2016 07:51

Awhile ago, Foxidrive helped me with some code to output some data from a file into another and show it based on a couple of parameters. The following is that code with a few modifications.

Code: Select all

@echo off
setlocal enabledelayedexpansion

set "xmlpath=\\server\developer\inetpub\Ftproot\XMLs"

if exist "%temp%\filterEOD.txt" del "%temp%\filterEOD.txt"
  If /i "%userdomain%" equ "DEV" (
     set "dom=PROD"
      set /p useris=Enter your production user name:
     set /p pw=Enter your production password:
      set Map1=Net use "%xmlpath%" !pw! /USER:!dom!\!useris! /PERSISTENT:NO
      !Map1!&pushd "%xmlpath%"
   ) ELSE (
      pushd "%xmlpath%"
   )
dir /o:-d /a-d "%xmlpath%\*.xml" |find "/" >"%temp%\filterEOD.txt"

set "found=0"
set "files=0"
(
for /f "usebackq tokens=1,2,3,4,*" %%a in ("%temp%\filterEOD.txt") do (
      set "f3=%%e"
      echo %%e %%a %%b %%c
      if !found! GTR 0 set /a files+=1
      IF /i "!f3:~0,3!" EQU "EOD" IF !found! GTR 0 (
            set /a files-=1
            echo(
            echo located !files! files between EOD files in total
            echo(
            goto :out
         )
      IF /i "!f3:~0,3!" EQU "EOD" set /a found+=1 && Echo( && ECHO(
   )
  if !found! LSS 2 (
     echo( & echo(
     echo Only !found! EOD file found
     echo !files! files were found from the first EOD file
 )
)>"%temp%\filterEOD2.txt"

:out
start "Filter EOD Files" "%temp%\filterEOD2.txt"

popd
del "%temp%\filterEOD.txt"
endlocal
exit /b


Now, I want to append the following code into this code to add additional output to the same file. Here is that code:

Code: Select all

for /f "tokens=1,2 delims=[]" %%a in (
   'dir /o-d /a-d /b^|find /n /v ""' ) do (
   echo %%~nxtb
   if %%a geq 14 goto :out
)
:out


I know this should be relatively simple but my brain isn't working today. Any suggestions appreciated.

I realize this is a bit vague. I got called away from my desk right as I was writing it so I just hit send hoping someone might offer suggestions. I have searched for the original post here and on SO but I can't find it. Both of these scripts run just fine on their own but I'd prefer them to be combined together. I've tried putting the second script into a function but that just hangs when running it. I did try adding a pause and @echo off at the top of the function but that didn't help either. I'm really stuck on this one.

-Matt

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Add additional text to existing output file.

#2 Post by aGerman » 29 Aug 2016 09:51

I just hope I understood your task ...

Code: Select all

@echo off
setlocal enabledelayedexpansion

set "xmlpath=\\server\developer\inetpub\Ftproot\XMLs"

if exist "%temp%\filterEOD.txt" del "%temp%\filterEOD.txt"
  If /i "%userdomain%" equ "DEV" (
     set "dom=PROD"
      set /p useris=Enter your production user name:
     set /p pw=Enter your production password:
      set Map1=Net use "%xmlpath%" !pw! /USER:!dom!\!useris! /PERSISTENT:NO
      !Map1!&pushd "%xmlpath%"
   ) ELSE (
      pushd "%xmlpath%"
   )
dir /o:-d /a-d "%xmlpath%\*.xml" |find "/" >"%temp%\filterEOD.txt"

set "found=0"
set "files=0"
(
for /f "usebackq tokens=1,2,3,4,*" %%a in ("%temp%\filterEOD.txt") do (
      set "f3=%%e"
      echo %%e %%a %%b %%c
      if !found! GTR 0 set /a files+=1
      IF /i "!f3:~0,3!" EQU "EOD" IF !found! GTR 0 (
            set /a files-=1
            echo(
            echo located !files! files between EOD files in total
            echo(
            goto :out1
         )
      IF /i "!f3:~0,3!" EQU "EOD" set /a found+=1 && Echo( && ECHO(
   )
  if !found! LSS 2 (
     echo( & echo(
     echo Only !found! EOD file found
     echo !files! files were found from the first EOD file
 )
)>"%temp%\filterEOD2.txt"
:out1

(
  for /f "tokens=1,2 delims=[]" %%a in (
     'dir /o-d /a-d /b^|find /n /v ""' ) do (
     echo %%~nxtb
     if %%a geq 14 goto :out2
  )
)>>"%temp%\filterEOD2.txt"
:out2

start "Filter EOD Files" "%temp%\filterEOD2.txt"

popd
del "%temp%\filterEOD.txt"

Steffen

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Add additional text to existing output file.

#3 Post by Matt Williamson » 29 Aug 2016 11:15

Thank you Steffen. This helped me very much.

Post Reply