This was the first search I found on google for `batch file copy file to all subfolders`.
Here's a way with [xcopy][1].
There's also [robocopy][2] but that would be too powerful for a simple task like this. (_I've used that for entire drive backups because it can use multi-threading_)
---
But, let us focus on **`xcopy`**.
This example is for saving to a file with the extension `.bat`. Just drop the additional `%` where there is two if running directly on the command line.
```
cd "D:\Software\destinationfolder"
for /r /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K
```
- `cd "D:\Software\destinationfolder"` change directory to the folder you want to copy the file to. Wrap this in quotes if the path has whitespaces.
- the `for` loop - [See help here][3]. Or type `for /?` in a command prompt.
- `/r` - Loop through files (recurse subfolders)
- `/d` - Loop through several folders
- `%%I` - `%%parameter`: A replaceable parameter
- `xcopy` - Type `xcopy /?` in the command line for lots of help. You may need to press <kbd>Enter</kbd> to read the entire help on this.
- `C:\temp\file.ext` - The file you want to copy
- `"%%~fsI"` - Expands `%%I` to a full pathname with short names only
- `/H` - Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files
- `/K` - Copies files and retains the read-only attribute on Destination files if present on the Source files. By default, xcopy removes the read-only attribute.
---
The last two parameters are just examples if you're having trouble with any read-only files and will retain the most important file properties.
[Lots more xcopy parameters here][4]
[xcopy examples here][5]
---
Just for completeness. This example below will copy the same file in each folder of the current directory and not any sub-folders. Just the `/r` option is removed for it to behave like this.
```
for /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K
```
[1]:
[To see links please register here]
[2]:
[To see links please register here]
[3]:
[To see links please register here]
[4]:
[To see links please register here]
[5]:
[To see links please register here]