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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
haggy
Posts: 11
Joined: 24 May 2018 03:39

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

#1 Post by haggy » 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?

T3RRY
Posts: 250
Joined: 06 May 2020 10:14

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

#2 Post by T3RRY » 18 Jan 2024 16:00

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.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

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

#3 Post by miskox » 19 Jan 2024 06:25

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

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

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

#4 Post by Batcher » 19 Jan 2024 23:07

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%"
)

Post Reply