[英]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.