0

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
0

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.

| improve this answer | |
0

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
| improve this answer | |
  • 1
    Welcome on the site! Your script looks wonderful, but please explain what it does and how. – peterh - Reinstate Monica Dec 6 '19 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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