解决方案
将这些文件中的字节放在一起很容易......但我不确定这是否会导致连续播放 - 我认为如果文件使用相同的比特率,但我不确定。
from glob import iglob
import shutil
import os
PATH = r'C:\music'
destination = open('everything.mp3', 'wb')
for filename in iglob(os.path.join(PATH, '*.mp3')):
shutil.copyfileobj(open(filename, 'rb'), destination)
destination.close()
这将创建一个单独的“everything.mp3”。包含C:\ music连接在一起的所有mp3文件的所有字节的文件。
如果要在命令行中传递文件的名称,可以使用 sys.argv [1:]
代替 iglob(...)
,等
其他提示
总结(并从 nosklo的答案中窃取),为了连接你做的两个文件:
destination = open(outfile,'wb')
shutil.copyfileobj(open(file1,'rb'), destination)
shutil.copyfileobj(open(file2,'rb'), destination)
destination.close()
这与:
相同cat file1 file2 > destination
嗯。我不会使用“行”。快速而肮脏的使用
outfile.write( file1.read() )
outfile.write( file2.read() )
)
不隶属于 StackOverflow