Get newest files from a text fie list

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Get newest files from a text fie list

#1 Post by SIMMS7400 » 16 Aug 2018 13:02

Hi Folks -

This is a simlar request to the one I posted the other day, however it's a bit more challenging.

I have a list of files with their date modified. Is there a way to parse this to always get to the latest two files?

Here is the text file:

Code: Select all

8/1/2018            	8:01:00 AM          	     	      2,112,338	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_01Aug2018.txt

8/2/2018            	8:00:00 AM          	     	      2,112,274	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_02Aug2018.txt

8/3/2018            	8:00:00 AM          	     	      2,112,482	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_03Aug2018.txt

8/4/2018            	8:00:00 AM          	     	      2,112,356	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_04Aug2018.txt

8/5/2018            	8:00:00 AM          	     	      2,112,476	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_05Aug2018.txt

8/6/2018            	8:01:00 AM          	     	      2,112,706	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_06Aug2018.txt

8/7/2018            	8:00:00 AM          	     	      2,112,136	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_07Aug2018.txt

8/8/2018            	8:02:00 AM          	     	      2,112,648	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_08Aug2018.txt

8/9/2018            	8:01:00 AM          	     	      2,113,504	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_09Aug2018.txt

8/10/2018           	8:00:00 AM          	     	      2,116,162	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_10Aug2018.txt

8/11/2018           	8:00:00 AM          	     	      2,116,008	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_11Aug2018.txt

8/12/2018           	8:01:00 AM          	     	      2,115,870	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_12Aug2018.txt

8/13/2018           	8:01:00 AM          	     	      2,115,766	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_13Aug2018.txt

8/14/2018           	8:00:00 AM          	     	      2,114,474	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_14Aug2018.txt

8/15/2018           	8:01:00 AM          	     	      2,114,944	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_15Aug2018.txt

8/16/2018           	8:00:00 AM          	     	      2,115,530	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_16Aug2018.txt

7/24/2018           	8:00:00 AM          	     	      2,110,170	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_24Jul2018.txt

7/25/2018           	8:00:00 AM          	     	      2,110,734	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_25Jul2018.txt

7/26/2018           	8:00:00 AM          	     	      2,112,100	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_26Jul2018.txt

7/27/2018           	8:00:00 AM          	     	      2,111,720	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_27Jul2018.txt

7/28/2018           	8:01:00 AM          	     	      2,111,636	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_28Jul2018.txt

7/29/2018           	8:00:00 AM          	     	      2,111,598	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_29Jul2018.txt

7/30/2018           	8:01:00 AM          	     	      2,111,362	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_30Jul2018.txt

7/31/2018           	8:01:00 AM          	     	      2,112,462	Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_31Jul2018.txt

8/1/2018            	8:00:00 AM          	     	         73,416	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_01Aug2018.txt

8/2/2018            	8:00:00 AM          	     	         73,982	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_02Aug2018.txt

8/3/2018            	8:00:00 AM          	     	         73,986	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_03Aug2018.txt

8/4/2018            	8:00:00 AM          	     	         74,300	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_04Aug2018.txt

8/5/2018            	8:00:00 AM          	     	         74,300	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_05Aug2018.txt

8/6/2018            	8:00:00 AM          	     	         74,286	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_06Aug2018.txt

8/7/2018            	8:00:00 AM          	     	         74,318	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_07Aug2018.txt

8/8/2018            	8:00:00 AM          	     	         74,474	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_08Aug2018.txt

8/9/2018            	8:00:00 AM          	     	         74,786	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_09Aug2018.txt

8/10/2018           	8:00:00 AM          	     	         74,474	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_10Aug2018.txt

8/11/2018           	8:00:00 AM          	     	         74,610	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_11Aug2018.txt

8/12/2018           	8:00:00 AM          	     	         74,610	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_12Aug2018.txt

8/13/2018           	8:00:00 AM          	     	         74,816	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_13Aug2018.txt

8/14/2018           	8:00:00 AM          	     	         74,816	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_14Aug2018.txt

8/15/2018           	8:00:00 AM          	     	         75,236	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_15Aug2018.txt

8/16/2018           	8:00:00 AM          	     	         75,222	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_16Aug2018.txt

7/26/2018           	8:00:00 AM          	     	         72,264	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_26Jul2018.txt

7/27/2018           	8:00:00 AM          	     	         72,530	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_27Jul2018.txt

7/28/2018           	8:00:00 AM          	     	         72,668	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_28Jul2018.txt

7/29/2018           	8:00:00 AM          	     	         72,790	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_29Jul2018.txt

7/30/2018           	8:00:00 AM          	     	         72,426	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_30Jul2018.txt

7/31/2018           	8:00:00 AM          	     	         73,244	Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_31Jul2018.txt
So the two newest files would be as such:
Rave_Active_Trial_Site_Enrollment_CLIENT.MDSOL.COM_16Aug2018.txt
Rave_Active_Trial_Site_Enrollment_CLIENT-ravex.mdsol.com_16Aug2018.txt
Thanks!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Get newest files from a text fie list

#2 Post by Squashman » 16 Aug 2018 13:09

I think you mean the newest file from each respective base file name before the date.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Get newest files from a text fie list

#3 Post by Aacini » 16 Aug 2018 15:14

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Note that this is a TAB: ---v
(for /F "tokens=1,2,3,7 delims=/	 " %%a in (input.txt) do (
   set /A "YMD=100000000-(%%c*10000+%%a*100+%%b)"
   echo !YMD! %%d
)) > temp.txt

set "i=0"
for /F "tokens=2" %%a in ('sort temp.txt') do (
   set /A i+=1
   if !i! leq 2 echo %%a
)
del temp.txt
Antonio

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Get newest files from a text fie list

#4 Post by SIMMS7400 » 17 Aug 2018 04:30

Hi Antonio -

Wow thank you so much! That's slicker than whale snot!!!

Have a great day!

Post Reply