Search code examples
windowsshellbatch-filecmd

copy files recursively using batch script


I have this code to copy files recursively from one folder to another.

set COMP_PATH=C:\Users\bose\Documents\test-download

cd C:\Users\bose\Desktop\downloaddir_nec
for /R %%f in (*.*) do copy /y %%f %COMP_PATH%
cd ..

This works fine as long as the folders I am recursing through don't have commas in them. I get this output when the folders have commas: enter image description here

How do I fix this? I want to copy the contents of all folders, recursively.

Thank you.


Solution

  • Just put the path in double quotes.

     set COMP_PATH=C:\Users\bose\Documents\test-download
        cd C:\Users\bose\Desktop\downloaddir_nec
        for /R %%f in (.) do copy /y "%%f" "%COMP_PATH%"
        cd ..