1

I'm trying a very simple batch script, but I must be missing something obvious. The idea is to copy all files from a source folder and from its subfolders to one destination folder. Both source and destination folder can be set manually.

The code below works, but it only copies the files of the source folder and not the files from the source subfolders. I guess it's because I use the src variable that it only looks into that folder, and not its subfolders.

set /p src=Enter source folder:
set /p dst=Enter destination folder:
md %dst%


 for /r %%i in (%src%) do copy "%%i" %dst%  

pause

I based it on the code below that I found on this forum. This one working, including copying the subfolders, but as I mentioned before, I can't define the (main) source folder, or I have to put the batch script in the folder I want to use as source folder:

for /r %%i in (*) do copy "%%i" %dst%

Thanks a lot!

0

1 Answer 1

1
for /r "%src%" %%i in (*) do copy "%%i" "%dst%"

Here's more detailed help for FOR /R

Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly! Thanks a lot, npocmaka!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.