assuming your date format is dd/mm/yyyy
try this:
@ECHO OFF &SETLOCAL
set "mydate=%date:/=-%"
for /d %%a in (D:\test*) do (
if exist "%%~a\%mydate%\" (
robocopy "%%~a\%mydate%" "X:\path\to\destination\folder"
)
)
Question
Hi I have been using Robocopy to backup files and now i need to do something like this
"robocopy [D:\test1\21-09-2013\sample.txt] [destination]"
here i have a lot of folders as Test1,test2,...testn. and beneath every test folders there are date wise folder.
My Question is How can i create a batch file to skip the test and copy only folder with Current date i.e something like this
"robocopy [D:\*\21-09-2013\sample.txt] [destination]"
so that it should get all the folders with current date copied.
Solution
assuming your date format is dd/mm/yyyy
try this:
@ECHO OFF &SETLOCAL
set "mydate=%date:/=-%"
for /d %%a in (D:\test*) do (
if exist "%%~a\%mydate%\" (
robocopy "%%~a\%mydate%" "X:\path\to\destination\folder"
)
)
OTHER TIPS
This may work in XP Pro and higher:
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
for /d /r "d:\" %%a in (*) do (
if "%%~nxa"=="%datestamp%" robocopy "%%a" "destination"
)