简体   繁体   中英

Batch: copy content of one txt file into another

Hi this is what i want to do:

I define a directory eg C:\\TEXT . If a txt file is posted/generated/moved into that directory, it opens the txt file copies its content, generates a new txt file, pastes that content into the new file and deletes the old one, is that possible?

It is fine if both txt files have pre-defined names.

Thanks a lot if anyone can help here!

You should be able to do something like:

TYPE 1.TXT > FINAL.TXT
TYPE 2.TXT >> FINAL.TXT

Note: the ">" will over-write. The ">>" will append or add to a file.

Hope this helps!

The following will accomplish the same with Boxed headings for every text file or batch file depending on your choice. Simply change the *.txt to *.bat or any text based file and the output will have a boxed heading of the filename along with the actual text from inside.

 @echo off
 ::If the file "Allbatchfiles.txt exists in the running folder then delete it. 
 IF EXIST Allbatchfiles.txt (
    del Allbatchfiles.txt
)
 :: For every file with the ".bat" extention Make an entry with 
 :: a Boxed heading of the filename and the contents of the file
 :: and output to the file Allbatchfiles.txt

 for %%f in (*.bat) do echo. >>AllBatchfiles.txt && echo ============================================ >>AllBatchfiles.txt && echo ----------"%%f"---------- >> AllBatchfiles.txt && echo ============================================ >>AllBatchfiles.txt && type "%%f" >>AllBatchfiles.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM