1

How to copy a folder which is contain date formate(DDMMYYYY) as folder name and folder name will differ from month to month. How can I create batch file for this.

1
  • You may not need grep - but you haven't supplied enough details about the task. Is it the current month you are copying? Is there only one folder inside the subdirectory? Give examples.
    – foxidrive
    Sep 7, 2013 at 23:56

1 Answer 1

2
@echo off &setlocal
set "startfolder=."
set "targetfolder=C:\destination"
cd /d "%startfolder%"
for /f "delims=" %%a ('dir /ad /b ^|grep -E "(([12][0-9]|0[1-9])02|(30|[12][0-9]|0[1-9])(0[469]|11)|(3[01]|[12][0-9]|0[1-9])(0[13578]|1[02]))[0-9]{4}"') do (
    md "%targetfolder%\%%~nxa"
    copy "%%~a" "%targetfolder%\%%~nxa"
)

findstr doesn't have enough Regex capabilities, you need grep for Windows.

Not the answer you're looking for? Browse other questions tagged or ask your own question.