Extract Values From Todays Date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ZayaMia
Posts: 14
Joined: 25 Apr 2017 02:54

Extract Values From Todays Date

#1 Post by ZayaMia » 21 May 2017 20:26

Hey everyone,

My current .batch is extracting specific values from XML files which I need.

The problem is that I only need the values/data from todays date.

Therefore, it should only extract from the newest XML files. (from today)

The Code:

Code: Select all

@echo off & setlocal enabledelayedexpansion
(for /F "tokens=1,2 delims=<>" %%a, in ('findstr "Name=\"Riven\" test=\"Plat32\"" *.xml') do (
 set "list=%%b"
 for /F "delims=" %%c in (^"!list: ^=^
% Do NOT remove this line %
!^") do set %%c
 if "!Name!+!test!" equ ""Riven"+"Plat32"" (
   for /F "tokens=1* delims=:" %%f in ("%%a") do (
    echo %%f, !testTime!, %%~tf, !errorCount!
   )
 )
)) > Outputfile.txt
start notepad outputfile.txt
goto :eof


Is it possible to add a certain command to extract only todays files?

Thanks for any help in advance !

igor_andreev
Posts: 16
Joined: 25 Feb 2017 12:55
Location: Russia

Re: Extract Values From Todays Date

#2 Post by igor_andreev » 21 May 2017 21:25

You can find todays files here: dir /a-d /od /t[cw] *.xml | findstr %date%

ZayaMia
Posts: 14
Joined: 25 Apr 2017 02:54

Re: Extract Values From Todays Date

#3 Post by ZayaMia » 21 May 2017 21:46

You can find todays files here: dir /a-d /od /t[cw] *.xml | findstr %date%


Thank you for your quick response !

Pardon me. I'am really new to programming and .batch.

Where do I have to add this code properly? :oops:

igor_andreev
Posts: 16
Joined: 25 Feb 2017 12:55
Location: Russia

Re: Extract Values From Todays Date

#4 Post by igor_andreev » 22 May 2017 06:02

ZayaMia wrote:Where do I have to add this code properly? :oops:


I don't know. It's your computer, your xml-files and your batch :)

What do you mean as 'today's files'? Created today or last modified today?
Type in command line: dir /?
What do you need, only '/tc' or '/tw'?
Which column of your 'dir' output contains the file names? It's regionally dependent.
Type in command line: dir /a-d /od /tw *.xml | findstr %date%
For this example file names in 5th column:

Code: Select all

17/05/22  01:23 PM             1,108 file.xml
17/05/22  01:37 PM               220 another file.xml

In my computer file names in 4th column:

Code: Select all

22.05.2017  13:23             1 108 file.xml                                                     
22.05.2017  13:37               220 another file.xml     

Eg. you can change '*.xml' in your batch file to '%1' and call batch from command line:

Code: Select all

for /f "tokens=3*" %a in ('dir /a-d /od /tw *.xml  ^| findstr %date% ') do call yourbatch.cmd "%b"

Code above works(i hope) if file names in 4th column. For 5th column 'tokens=4*'.
How much 'todays files' usually you have? You can place file names to variable inside batch file, e.g.:

Code: Select all

@echo off & setlocal enabledelayedexpansion
for /f "tokens=3*" %%a in ('dir /a-d /od /tw *.xml ^| findstr %date% ') do set todays_files="%%b" !todays_files!

(for /F "tokens=1,2 delims=<>" %%a, in ('findstr "Name=\"Riven\" test=\"Plat32\"" !todays_files!') do (
....

Many variants of how to use 'dir' output.

ZayaMia
Posts: 14
Joined: 25 Apr 2017 02:54

Re: Extract Values From Todays Date

#5 Post by ZayaMia » 23 May 2017 02:41

Thanks for your detailed answer.

With today's files I mean last modified.

Though I tried around with dir and didn't work so far :( . I'll keep on trying.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Extract Values From Todays Date

#6 Post by penpen » 23 May 2017 04:18

I remember this should work for you:

Code: Select all

forfiles /M "*.xml" /D +0
(Hopefully it should work.)


penpen

Post Reply