List XML files after a certain file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: List XML files after a certain file

#16 Post by foxidrive » 01 Oct 2015 10:49

MattW76 wrote:

Code: Select all

echo located !files! files in total>>"%temp%\filterEOD2.tmp"



Matt, is that the line you want the date and time in?
Do you want the current date and time?

MattW76
Posts: 17
Joined: 24 Aug 2015 07:59

Re: List XML files after a certain file

#17 Post by MattW76 » 01 Oct 2015 11:22

Hi Foxidrive

I would like the last modified date and time after the EODMess file. So the first line and the 2nd to last.

Code: Select all

EODMESS_20150930_1076295166.xml    Date & Time
.....
Other files
.....
EODMESS_20150930_1076295166.xml    Date & Time
located 6006 files in total

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: List XML files after a certain file

#18 Post by foxidrive » 01 Oct 2015 12:32

In case you saw the first version, test this one Matt.
The first version I posted in this post would suffer from the time delay also, so I modified the code a little more.

I've also modified where your code adds the total file number - there was no reason to do so, I just couldn't resist.


Code: Select all

@echo off
set "xmlpath=\\Server1\developer\inetpub\Ftproot\XMLs\*.xml"
dir /o:-d "%xmlpath%" |find "/" >"%temp%\filterEOD.tmp"
set "found="
set "files="
setlocal enabledelayedexpansion
(
for /f "usebackq tokens=1,2,3,4,*" %%a in ("%temp%\filterEOD.tmp") do (
      set "f3=%%e"
      echo %%e %%a %%b %%c
      set /a files+=1
      IF /i "!f3:~0,3!" EQU "EOD" IF defined found (
                  echo(
                  echo located !files! files in total
                  echo(
                  goto :out
      )
      IF /i "!f3:~0,3!" EQU "EOD" set "found=1"
   )
)>"%temp%\filterEOD2.tmp"
:out
start "Filter EOD Files" "%temp%\filterEOD2.tmp"
del "%temp%\filterEOD.tmp"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: List XML files after a certain file

#19 Post by foxidrive » 01 Oct 2015 12:51

That should write the date and time to the end of each filename - if you change

echo %%e %%a %%b %%c

to

echo %%a %%b %%c %%e

then it will format nicely and be easier to read with date/time at the beginning of each line.
If you really only want the date and time on the first and last filename then it's trickier.

EDIT: I had to review the thread to recall what was happening and I'm now a little confused.

The EODMESS files must be what you called ABC files originally - and I was wondering if the file count was actually supposed to be the number of files between the two EOD files - or is the count of files actually ok?

MattW76
Posts: 17
Joined: 24 Aug 2015 07:59

Re: List XML files after a certain file

#20 Post by MattW76 » 01 Oct 2015 13:38

Thanks Foxi! Can I throw a monkey wrench in the works? If 2 Eod files aren't found, I need it to say that. Here is what I was attempting:

Code: Select all

@echo off
set "xmlpath=\\server1\developer\inetpub\Ftproot\XMLs\*.xml"
dir /o:-d "%xmlpath%" |find ":" |find /v "\" >"%temp%\filterEOD.tmp"
set "found="
set "files="
setlocal enabledelayedexpansion
(
for /f "usebackq tokens=1,2,3,4,*" %%a in ("%temp%\filterEOD.tmp") do (
      set "f3=%%e"
      echo %%e %%a %%b %%c
      set /a files+=1
      IF /i "!f3:~0,3!" EQU "EOD" IF defined found (
                  echo(
                  echo located !files! files in total
                  echo(
                  goto :out
      ) ELSE (
         If !Found! NEQ 1 Echo Only One EOD file found
      )
      IF /i "!f3:~0,3!" EQU "EOD" set "found=1"
   )
)>"%temp%\filterEOD2.tmp"
:out
start "Filter EOD Files" "%temp%\filterEOD2.tmp"
del "%temp%\filterEOD.tmp"


Sorry about that. I forgot I originally used ABC in place of EOD. The count was the number of files between the EOD files.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: List XML files after a certain file

#21 Post by foxidrive » 02 Oct 2015 00:12

Test this - several changes - it should report if only one or no EOD files are found
It should count the files between the two EOD files, or after the first EOD file if only one is found.

Code: Select all

@echo off
set "xmlpath=\\Server1\developer\inetpub\Ftproot\XMLs\*.xml"
dir /o:-d /a-d "%xmlpath%" |find "/" >"%temp%\filterEOD.tmp"
set "found=0"
set "files=0"
setlocal enabledelayedexpansion
(
for /f "usebackq tokens=1,2,3,4,*" %%a in ("%temp%\filterEOD.tmp") 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
   )
  if !found! LSS 2 (
     echo(
     echo Only !found! EOD file found
     echo !files! files were found from the first EOD file
 )
)>"%temp%\filterEOD2.tmp"
:out
start "Filter EOD Files" "%temp%\filterEOD2.tmp"
del "%temp%\filterEOD.tmp"

MattW76
Posts: 17
Joined: 24 Aug 2015 07:59

Re: List XML files after a certain file

#22 Post by MattW76 » 02 Oct 2015 09:11

Thanks for your help again Foxidrive. I'm not getting the output I'm expecting.

Here is what I'm getting with either 1 or 2 EOD messages:

Code: Select all

EODMESS_20151001_1076445661.xml 10/01/2015 05:56 PM

located -1 files between EOD files in total

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: List XML files after a certain file

#23 Post by foxidrive » 02 Oct 2015 17:28

Try the code again Matt - I changed

IF defined found (
to
IF !found! GTR 0 (

because I had initialised the found variable, and it was stopping as soon as it saw an EOD file because the variable was defined.

MattW76
Posts: 17
Joined: 24 Aug 2015 07:59

Re: List XML files after a certain file

#24 Post by MattW76 » 05 Oct 2015 07:19

Working perfectly now Foxidrive, thanks again!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: List XML files after a certain file

#25 Post by foxidrive » 08 Oct 2015 04:21

MattW76 wrote:Working perfectly now Foxidrive, thanks again!


No worries. :)

Post Reply