Find command most recently created file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Find command most recently created file

#1 Post by karzer » 09 Aug 2011 02:48

Hi, I'm using this script on my server

Code: Select all

type D: \ 09082011.txt | find / c "aborted"

the following problem, every day here consists of a new file, the most recently created file to use this command. How can I do?

Code: Select all

type D: \ ?????. txt | find / c "aborted"
Date created from last

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Find command most recently created file

#2 Post by dbenham » 09 Aug 2011 22:32

Code: Select all

for /f %%f in ('dir /b /o-d /tw d:\*.txt') do find /c "aborted" %%~ff & goto :quitLoop
:quitLoop

Dave Benham

karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Re: Find command most recently created file

#3 Post by karzer » 10 Aug 2011 03:11

Thank you very much for your interest, just want to get some value, how can I do?

I want this value is only 73



now I have received results

Code: Select all

---------- D:\oracle.TXT: 73

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Find command most recently created file

#4 Post by dbenham » 10 Aug 2011 05:21

Sorry - I think FIND /C "aborted" filename is faster than TYPE filename | FIND /C "aborted". But I didn't test for differences in output. Just need to revert to your syntax.

Also I reread your requirements and saw you wanted the most recent *.txt created. I was getting the most recent *.txt written to. So I changed the DIR option from /TW to /TC.

Here is the fix:

Code: Select all

for /f %%f in ('dir /b /o-d /tc d:\*.txt') do type %%~ff | find /c "aborted" & goto :quitLoop
:quitLoop


Dave Benham

karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Re: Find command most recently created file

#5 Post by karzer » 12 Aug 2011 03:50

Problem solved...

Thank you very much for your interest

Post Reply