Page 1 of 1

How to copy a txt file into multiple txt files in a destination folder

Posted: 18 Jan 2024 13:13
by haggy
Hello All,
I tried copying the content of a txt file into multiple txt files in a destination folder but not getting the expected result. I've tried :
"Copy my file.txt floder\×.txt" but it's not updating all the txt files. Can someone help me out?

Re: How to copy a txt file into multiple txt files in a destination folder

Posted: 18 Jan 2024 16:00
by T3RRY
haggy wrote:
18 Jan 2024 13:13
Hello All,
I tried copying the content of a txt file into multiple txt files in a destination folder but not getting the expected result. I've tried :
"Copy my file.txt floder\×.txt" but it's not updating all the txt files. Can someone help me out?
why would you expect it to?
Copy cannot append to files - it creates or overwrites them, and as it can only create A destination file, it cannot accept wildcards for the Destination file.

In other words, whilst copy can copy multiple files into a single file, it cannot copy a single file into multiple files.

I suggest referring to the help output of commands within cmd.exe
There also sites like https://ss64.com/nt/ that offer detailed command explanations and usage examples.

Re: How to copy a txt file into multiple txt files in a destination folder

Posted: 19 Jan 2024 06:25
by miskox

Code: Select all

copy file.txt folder\file1.txt
copy file.txt folder\file2.txt
copy file.txt folder\file3.txt
copy file.txt folder\file4.txt
I wanted to use FOR but you take a look: viewtopic.php?p=38525#p38525

Saso

Re: How to copy a txt file into multiple txt files in a destination folder

Posted: 19 Jan 2024 23:07
by Batcher
1.bat

Code: Select all

@echo off
set "OldFile=C:\Test\1.txt"
set "NewFolder=C:\Test\To"
for /f "delims=" %%i in ('dir /b /a-d "%NewFolder%\*.txt"') do (
    >>"%NewFolder%\%%i" echo,
    >>"%NewFolder%\%%i" type "%OldFile%"
)