Reputation: 37
I want to copy a file and paste that file to multiple folders.
Designation path : c:\exam\*\mark
, *
is subject. I have many folders with different subjects.
I am using a batch file like,
for /d %%a in ("c:\exam\*\mark") do copy "C:\name\add.txt" "%%a"
but this is not working for me, please give a suggestion to correct this code.
Upvotes: 2
Views: 2736
Reputation: 82192
for /d
can't handle wildcharacters inside a path, it's only allowed in the last element.
But you can simply try to copy to the destination, if the destination path doesn't exist it fails and the error will redirected to nul.
Or you can test first if the destination exists, like Endoro showed.
for /d %%a in ("c:\exam\*") do (
copy "C:\name\add.txt" "%%a\mark\" 2> nul
)
Upvotes: 3
Reputation: 37569
one loop is enough:
for /d %%a in (c:\exam\*) do if exist "%%~a\mark\" copy "C:\name\add.txt" "%%~a\mark"
Upvotes: 7