a little batch help, please.

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
Hi all,

I'm trying to copy the last modified file in dos.

I can use 'dir /OD' to search a directory for the last modified file, but how do I capture the top result as a variable???

any ideas??

Cheers in advance :)
 
dir /od give the most recent in descending order, the "top result" is actually the oldest modified date. you'r second sentence suggests you meant the last result i.e. the most recently modified file (not directory),(and not the top result, the oldest) then the command
Code:
for /f "delims=" %%a in ('dir /b /od /a-d') do set mostRecent=%%a
echo Most recently modified file is: %mostRecent%

I always make sure my dir commands have a path this can avoid many probs.somthing like:
Code:
echo Working from: %pathToCheck%
for /f "delims=" %%a in ('dir %pathToCheck% /b /od /a-d') do set mostRecent=%%a
echo Most recently modified file is: %mostRecent%

And make sure %pathToCheck% is correct.
 
Back
Top Bottom