I was doing something similar. I have all my files in a folder, so I was using the glob module and the wildcard (*) symbol. This may help point you in the right direction.
I am using python 2.7 with Mac OS. So my path is referencing the path to my folder.
My files ONLY HAVE 1 line....could you post some details about the first line of your files??
I am writing to an outfile... merge_BLASTP_results.out
for file in glob.glob('/Users/sueparks/BlastP_Results/*'):
myfile = open(file,'r') #open each file
lines = myfile.readlines() # read lines of each file
with open('merge_BLASTP_results.out', 'a') as f:
for line in lines:
f.write(line) # write lines to new file
So, if I have 200 protein files that start with 'P_1'...and end with '.txt', but I also have another 100 text files that are labeled rna1.txt,rna2.txt,....Can you show me how to exclusively work with the P_1.txt files?? I seen an example with the wild card (*), but I was curious about what you thought??