I have a series of files similar to that
1A2B_A.txt, 1A2B_2C.txt, 1A2B_DF.txt,
1B23_D.txt, 1B23_B.txt, 1B23_25.txt, and many more
I want to combine each three files starting with the same four code before the "_"
Thanks in advance
I have a series of files similar to that
1A2B_A.txt, 1A2B_2C.txt, 1A2B_DF.txt,
1B23_D.txt, 1B23_B.txt, 1B23_25.txt, and many more
I want to combine each three files starting with the same four code before the "_"
Thanks in advance
Something like this, can not test without those files:
import os
## assumes curdir is directory with the text files to process
if not os.path.isdir(os.path.join(os.curdir,'joined')):
os.mkdir(os.path.join(os.curdir,'joined'))
for textfile in (fn for fn in os.listdir(os.curdir)
if fn.endswith('.txt') and fn[4]=='_'):
begin,_,end = textfile.partition('_')
open( os.path.join(os.curdir,
'joined',
begin+'.txt'),
'a').write(open(textfile).read())
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.