Get newest directory ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sabercats
Posts: 6
Joined: 18 May 2011 15:54

Get newest directory ?

#1 Post by sabercats » 18 May 2011 16:10

How do you get an newest directory in a folder and copy that new folder to another place?
1. Go to \\Where\we\get\new\folder
2. Call that latest foldername = recent
3. xcopy \\Where\we\get\new\folder\recent \\Where\we\make\a\backup\ /D/S/E

Thanks,

xl1000
Posts: 10
Joined: 01 Feb 2011 06:10

Re: Get newest directory ?

#2 Post by xl1000 » 20 May 2011 09:14

Try something like this:

Code: Select all

@echo off
ECHO.
ECHO Show most recent folder
ECHO.

set recent=
set unc_path=\\Where\we\get\new\folder

FOR /F %%i IN ( 'dir /od /ad /b %unc_path%\' ) DO SET recent=%%i

ECHO Recent path=%recent%
ECHO.
ECHO XCOPY %recent% \\target\that\you\want /D/S/E
ECHO.


sabercats
Posts: 6
Joined: 18 May 2011 15:54

Re: Get newest directory ?

#3 Post by sabercats » 25 May 2011 17:20

Somehow i tried yours and it did not work, but this work for me

Code: Select all

@echo off
set indir=\\Where\we\get\new\folder
set outdir=\\Where\we\make\a\backup

for /f "usebackq delims=" %%i in (`dir "%indir%" /ad /o-d /b`) do (
    set recent=%%i
    goto cont
)

:cont
%
xcopy \\Where\we\get\new\folder\%recent% \\Where\we\make\a\backup\%recent%  /D /S /E /Y


Thanks

Post Reply