Page 1 of 1

Get newest directory ?

Posted: 18 May 2011 16:10
by sabercats
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,

Re: Get newest directory ?

Posted: 20 May 2011 09:14
by xl1000
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.


Re: Get newest directory ?

Posted: 25 May 2011 17:20
by sabercats
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