Reputation: 75
I have this batch file now that copies example.jpg
from C:\Temp
to the Test-folder and all its subfolders.
I would like it to copy the file only 1 subfolder deep in the Test-folder.
For example copy the picture to Test\subfolder
but NOT to Test\subfolder\subfolder2
@echo off
for /r "C:\Temp\Test" %%f in (.) do (
copy "C:\Temp\example.jpg" "%%~ff" > nul
)
PAUSE
Upvotes: 1
Views: 2345
Reputation: 200293
Don't use recursion if you want to go only 1 level deep. Try this instead:
@echo off
set src=C:\Temp\example.jpg
set dst=C:\Temp\Test
copy "%src%" "%dst%" >nul
for /d %%d in ("%dst%\*") do (
copy "%src%" "%%~fd" >nul
)
Upvotes: 1
Reputation: 80023
@ECHO OFF
SETLOCAL
SET destroot=c:\temp
FOR /f "delims=" %%i IN ( ' dir /ad/b "%destroot%"' ) DO ECHO COPY "c:\temp\example.jpg" "%destroot%\%%i\"
Simply shows what the batch PROPOSES to do. Remove the ECHO
keyword to activate the copy and add >nul
to suppress the "copied" message
Upvotes: 0