批处理:将一个txt文件的内容复制到另一个文件中

时间:2015-10-29 13:26:19

标签: windows batch-file text-files

嗨,这就是我想要做的事情:

我定义了一个目录,例如C:\TEXT。 如果将txt文件发布/生成/移动到该目录中,则会打开txt文件复制其内容,生成新的txt文件,将该内容粘贴到新文件中并删除旧的,可能吗?

如果两个txt文件都有预定义的名称,则可以。

非常感谢,如果有人可以在这里帮忙的话!

2 个答案:

答案 0 :(得分:1)

您应该可以执行以下操作:

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

注意:">"会覆盖。 ">>"将追加或添加到文件中。

希望这有帮助!

答案 1 :(得分:0)

以下内容将根据您的选择为每个文本文件或批处理文件的Boxed标题完成相同的操作。只需将* .txt更改为* .bat或任何基于文本的文件,输出将包含文件名的带框标题以及内部的实际文本。

 @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
相关问题