Retrieving the last file created in a CMD file DO loop

S

Scott

Hi,

I hope this is an appropriate newsgroup for this msg. I did search the
newsgroups and this one seemed the most appropriate.

I have a logging directory with a bunch of files named like this:

foo.log.23Feb2004_15_38_32
foo.log.25Dec2004_15_38_32
foo.log.14Jan2004_15_38_32
foo.log.07Jun2004_15_38_32
foo.log.17Mar2004_15_38_32

So, the files do not sort in chronological order. Yes, the naming
convention is brain-dead, but is non-configurable.

I have a batch file like so, where I am invoking an editor on all the
desired log files of interest, in order to debug problems:

@echo off

FOR %%a IN (D:\Logs\TheApplication\authentication\*) DO set auth=%%a
FOR %%z IN (D:\Logs\TheApplication\authorization\*) DO set az=%%z

set FILE1=D:\Logs\TheApplication\foo\bar.log
set FILE2=D:\Logs\TheApplication\bar\foo.log
....
set FILE10=%auth%
set FILE11=%az%

"C:\Program Files\TextPad 4\TextPad.exe" "%FILE1%" "%FILE2%" ... "%FILE10%"
"%FILE11%"

In the FOR loop above, is there a way to get the files returned in last
modification date order, instead of filename sorted order, so that the
variables auth and az will be set to the proper files? I'd prefer to use
CMD rather than PERL since PERL won't be on all the machines that may use
this CMD file. If you do suggest alternatives, hopefully it will be using
tools available in a standard install of W2K.

Thanks,
Scott
 
P

Phil Robyn [MVP]

Scott said:
Hi,

I hope this is an appropriate newsgroup for this msg. I did search the
newsgroups and this one seemed the most appropriate.

I have a logging directory with a bunch of files named like this:

foo.log.23Feb2004_15_38_32
foo.log.25Dec2004_15_38_32
foo.log.14Jan2004_15_38_32
foo.log.07Jun2004_15_38_32
foo.log.17Mar2004_15_38_32

So, the files do not sort in chronological order. Yes, the naming
convention is brain-dead, but is non-configurable.

I have a batch file like so, where I am invoking an editor on all the
desired log files of interest, in order to debug problems:

@echo off

FOR %%a IN (D:\Logs\TheApplication\authentication\*) DO set auth=%%a
FOR %%z IN (D:\Logs\TheApplication\authorization\*) DO set az=%%z

set FILE1=D:\Logs\TheApplication\foo\bar.log
set FILE2=D:\Logs\TheApplication\bar\foo.log
...
set FILE10=%auth%
set FILE11=%az%

"C:\Program Files\TextPad 4\TextPad.exe" "%FILE1%" "%FILE2%" ... "%FILE10%"
"%FILE11%"

In the FOR loop above, is there a way to get the files returned in last
modification date order, instead of filename sorted order, so that the
variables auth and az will be set to the proper files? I'd prefer to use
CMD rather than PERL since PERL won't be on all the machines that may use
this CMD file. If you do suggest alternatives, hopefully it will be using
tools available in a standard install of W2K.

Thanks,
Scott

Hi, Scott:

May the following will give you some ideas:
- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>for /f "tokens=*" %a in ('dir /od test\xc*.cmd ^| find "/"') do @echo %a
02/26/2001 04:32p 558 xcombine.cmd
02/26/2001 04:35p 589 xcombine1.cmd
03/03/2001 12:14a 848 xcombine2.cmd
03/12/2001 02:55p 918 xcombine3.cmd
07/14/2001 01:22a 532 xchange.cmd
09/18/2001 09:49p 489 xcombine4.cmd
10/22/2001 12:25a 644 xcmulti.cmd
01/14/2002 03:51p 552 xctmjobstats.cmd
08/07/2002 10:44a 1,252 xCOA.cmd
01/23/2004 02:59p 908 xc.cmd

C:\cmd>for /f "tokens=*" %a in ('dir /b /od test\xc*.cmd ') do @echo %a
xcombine.cmd
xcombine1.cmd
xcombine2.cmd
xcombine3.cmd
xchange.cmd
xcombine4.cmd
xcmulti.cmd
xctmjobstats.cmd
xCOA.cmd
xc.cmd
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
 
W

Waldo

Phil Robyn said:
Hi, Scott:

May the following will give you some ideas:
- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>for /f "tokens=*" %a in ('dir /od test\xc*.cmd ^| find "/"') do @echo %a
02/26/2001 04:32p 558 xcombine.cmd
02/26/2001 04:35p 589 xcombine1.cmd
03/03/2001 12:14a 848 xcombine2.cmd
03/12/2001 02:55p 918 xcombine3.cmd
07/14/2001 01:22a 532 xchange.cmd
09/18/2001 09:49p 489 xcombine4.cmd
10/22/2001 12:25a 644 xcmulti.cmd
01/14/2002 03:51p 552 xctmjobstats.cmd
08/07/2002 10:44a 1,252 xCOA.cmd
01/23/2004 02:59p 908 xc.cmd

C:\cmd>for /f "tokens=*" %a in ('dir /b /od test\xc*.cmd ') do @echo %a
xcombine.cmd
xcombine1.cmd
xcombine2.cmd
xcombine3.cmd
xchange.cmd
xcombine4.cmd
xcmulti.cmd
xctmjobstats.cmd
xCOA.cmd
xc.cmd
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Thank you kindly. I didn't think to trap command output and look for little
used dir switches. Doh!

Usenet comes thru again.

Best Regards,
Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top