[CMD] Copy content of folder & its sub-folders recursively

@echo off

echo This script copy everything inside a folder to a new path, containing sub-folders.
echo.

set /p target_path="Enter path containing all files: "
set /p distin_path="Enter new path for re-grouped files: "
set /p filter_word="Exclud file name containing certain string (leave empty for none): "
set vcffile=*.*

C:
cd %target_path%

if defined filter_word (
    for /f "delims=" %%s in ('dir /b/a-d/s "%target_path%"\"%vcffile%"') do (
        echo Copying %%~ns to %distin_path%...
        echo %%s | findstr %filter_word% >nul && (
            copy /y "%%s" %distin_path% > null
        )
    )
) else (
    for /f "delims=" %%s in ('dir /b/a-d/s "%target_path%"\"%vcffile%"') do (
        echo Copying %%~ns to %distin_path%...
        copy /y "%%s" %distin_path% > null
    )
)

echo.
echo All file(s) copied.
pause

Leave a Reply