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,
Get newest directory ?
Moderator: DosItHelp
Re: Get newest directory ?
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 ?
Somehow i tried yours and it did not work, but this work for me
Thanks
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