简体   繁体   English

如何将一个txt文件中的文本添加到多个txt文件中

[英]How to prepend text from one txt file to multiple txt files

I have one intro.txt file with some text that I want to prepend to all.txt files我有一个 intro.txt 文件,其中包含一些我想添加到 all.txt 文件的文本

Example intro.txt示例 intro.txt

0
00:00:00,000 --> 00:00:10,000
Subtitle BY Name
Synced By Name

I want to append it to the first line我想把 append 放到第一行

File1.txt文件1.txt

    0
    00:00:00,000 --> 00:00:10,000
    Subtitle BY Name
    Synced By Name
    
    1
    00:00:11,000 --> 00:00:20,000 
    Hello
    2
    00:00:21,000 --> 00:00:30,000 
    How are you doing

File2.txt文件2.txt

    0
    00:00:00,000 --> 00:00:10,000
    Subtitle BY Name
    Synced By Name
    
    1
    00:00:11,000 --> 00:00:20,000 
    Hello
    2
    00:00:21,000 --> 00:00:30,000 
    How are you doing

I found this code "rename the file which should be appended to intro (or anything without.txt extension), then you can use a FOR loop over *.txt files in a batch file"我发现这段代码“重命名应该附加到介绍的文件(或任何没有 .txt 扩展名的文件),然后你可以在批处理文件中对 *.txt 文件使用 FOR 循环”

@echo off
for /R  "C:\Users\Mr-Oussama\Desktop\intro\MylistText" %%a in (*.srt) do type intro >> %%a
pause

It works fine.它工作正常。 But I want the text to appear on the first line, not at the end但我希望文本出现在第一行,而不是最后

I found this program when adding a text an error message appears我在添加文本时发现了这个程序,出现错误消息

PSA Insert Text to SRT PSA 将文本插入 SRT

Is there anyone with an idea of any program or required order?有没有人知道任何程序或要求的顺序? works on Windows适用于 Windows

I found this code Payton我找到了这个代码佩顿

import glob

for file in glob.glob('./*txt'):
    with open(file.replace('.txt', '-out.txt'), 'w') as outfile:
        with open(file) as infile:
            text = infile.readlines()
            text.insert(0, "header\n")

            outfile.write(''.join(text))

            infile.close()
    outfile.close()

He's working.他在工作。 Instead of writing a text, how do you specify a text?您如何指定文本,而不是编写文本? Like changing a text "header" to file path intro.txt header = \Desktop\new\intro.txt就像将文本“标题”更改为文件路径 intro.txt header = \Desktop\new\intro.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将两个.txt文件中的数据提取到一个新的.txt文件中? - How do I extract the datas from two .txt files into one new .txt file? 批处理文件从多个文件夹中的多个txt文件中提取文本 - Batch file to extract text from multiples txt files in multiples folders 从一个PyInstaller文件访问和创建.txt文件 - Access and create .txt files from a PyInstaller one-file 如何批量替换目录windows vista中的文件(从.txt.txt到.txt) - how to batch replace the files in a directory windows vista(from .txt.txt to .txt) 如何将目录中的所有* .txt文件写入一个文件中,并在输出文件的每一行中包含源文件名? - How to write all *.txt files in a directory into one file with source file name in each line in output file? 在多个.txt文件中查找字符串 - Find string in multiple .txt files 如何从txt文件中排除单词? - How to exclude words from txt file? 如何在 Gnuplot 中分别 plot 2 个文件数据?我有一个文件为“sin.txt”,另一个为“cos.txt”,我想在一张图上分别 plot - How to plot 2 files data separately in Gnuplot ?I have one file as “sin.txt” and other as “cos.txt” and i want to plot them separately on one graph 如何使用此批处理文件将所有* .txt文件从子文件夹复制到批处理文件文件夹? - How to copy all *.txt files from subfolder to batch file folder using this batch-file? 将文本导出到C中的.txt文件 - Exporting text to .txt file in C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM