1.

Solve : Assign most recent file to a variable. (curious)?

Answer»

Hi all,

Am trying to perform a bare listing of files in a particular format
(eg: %xDIR%\%xMCode%%xCCode%%xTType%.%Year:~2,2%%Month%%Day%.* ) and do the following ...

  • If no files ... return an error/flag value
  • if more than one file exiss ... return with a message
  • If one or more files ... return the value of the most recent file only
This isn't for anything right now, was wondering how it would be ACHIEVED in msdos/batch ... I know what I'd need to do in a unix environment.

Cheers,
Cameron.show samples of your file formats, and what you WANT to doHi ghostdog74 ...

I'd provided the file format in the initial post...
%xDIR%\%xMCode%%xCCode%%xTType%.%Year:~2,2%%Month%%Day%.*
For example: C:\...\USCBTT.080604.155015

What I WANTED to do was INDICATED in the dot points.
you can use the dir command to generate a file listing

these switches would seem relevant

/b ... generate a bare listing
/o:d ... in date order, earliest first
/o:-d ... in date order, latest first

/T:C ... use file creation date
/T:A ... use last access date
/T:W ... last written

You can add a wildcard to select the file(s) you require

e.g.

dir /b /o:-d /t:c [filespec]

You can use FOR to process the output.

You can use the IF EXIST test.






Discussion

No Comment Found