I want to copy from a folder with several subfolders all csv files to a single folder. But I only want files that are not older than 30 days.

This is what i have so far:

for /R C:\Source %%f in (*.csv) do copy %%f U:\Target

I know there are more possibilities with robocopy, but I can not use robocopy with my code:

for /R C:\Source %%f in (*.csv) do robocopy %%f U:\Target

2 Answers 2


You could use the forfiles command, which has the option to specify a minimum date.

forfiles /p C:\Source /m *.csv /s /c "cmd /c copy @path U:\Target" /d 22-10-2019

Unfortunately there is no way to specify ‘files not older than [n] days’, that's why I used a hardcoded date.


This will work for you:

for /f "tokens=* delims= " %%a in ('forfiles /p SourcePath /m *.csv /s /c "cmd /c echo @path" /d -30') do copy "%%~a" TargetPath
  • 1
    Welcome on the site! Your script looks wonderful, but please explain what it does and how.
    – peterh
    Dec 6, 2019 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .