Help write a DOS script to get the name of the most recent directory (creation time)

Hi guys, I need help getting the name of the most recent directory in a DOS script.

I found some information about getting the very last file that works, but I can't get this to work with directories.

For example, here is my directory:

drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:34 _200903_V20 drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:35 _200904_V21 drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:36 _200905_V22 drwxr-xr-x 2 usrpm Domain Users 0 Jun 29 10:38 _200906_V23 

I need my script to return me the most recent directory (V23). Then I will go to the directory and copy the file from it.

Thanks for any help!

+4
source share
2 answers

There is a link to two scripts that find the most recent file. I think the second is already doing exactly what you want, but you can change one of them to do what you need, I'm sure. I just googled β€œfind the latest batch file” and immediately found it.

Source Link .

Edited to add a script that works with directories:

 @echo off for /f "delims=" %%x in ('dir /od /b *.*') do set recent=%%x echo %recent% 

Output:

 C:\> recent.bat recent.bat C:\> mkdir newdir C:\> recent.bat newdir 

Looks like he works here.

+9
source

This should work:

 for /f "usebackq delims=" %%i in (`dir /ad /od /b`) do ( set LETESTDIR=%%i goto cont ) :cont echo %LETESTDIR% 
+4
source

All Articles