Page 1 of 1

Find command most recently created file

Posted: 09 Aug 2011 02:48
by karzer
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

Re: Find command most recently created file

Posted: 09 Aug 2011 22:32
by dbenham

Code: Select all

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

Dave Benham

Re: Find command most recently created file

Posted: 10 Aug 2011 03:11
by karzer
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

Re: Find command most recently created file

Posted: 10 Aug 2011 05:21
by dbenham
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

Re: Find command most recently created file

Posted: 12 Aug 2011 03:50
by karzer
Problem solved...

Thank you very much for your interest