I want to copy a file (file.txt) inside all folders of a given destination. I want to create a batch file that does the job, but I'm not so skilled in Windows batch syntax.
Windows – copy file to multiple folders via batch script
cmd.exewindows
cmd.exewindows
I want to copy a file (file.txt) inside all folders of a given destination. I want to create a batch file that does the job, but I'm not so skilled in Windows batch syntax.
Best Answer
You can use the advanced version of the
for
command available from Windows NT 4 onwards:You need something like this in a batch file:
The batch file works as follows:
The
for
command with the/D
switch iterates over all directories in a given path (here:%1
) and invokes a command on each iteration. Said command is the copy operation which copies the file into every directory.Of course, since the batch file is only a single line you can also execute it directly on the command line. Just note that the variable for
for
has only a single%
, then.