使用python2.5 合并某文件夹里所有文件,例如:(xxx.fasta)格式

根据关键词对文件进行拆解和合并,非常感谢!求python大侠,帮助学习python编程!不甚感激!251760860注明python

import os
dir_name = "c:\somefolder"
file_list = [f_name for f_name in os.listdir(dir_name) if os.path.isfile(f_name) and f_name.endswith('.fasta')]
combine_file_name = "combine.txt"
f_combine = open(combine_file_name,"w")
for f_in_name in file_list:
f = open(f_in_name,'r')
for line in f.readlines():
f_combine.write(line)
f.close()
f_combine.close()追问

不能用啊!只建了个combine.txt里面什么都没有!我里面均是fasta格式不用判断!
import os
a="C:\Users\Yin-Jinbao\Desktop\zhz"
files = os.listdir( a )
for b in files:
c=open(b)
e='e.txt'
f=open(e,'w')
f.write(c)
f.close()
Traceback (most recent call last):
File "", line 2, in
c=open(b)
IOError: [Errno 2] No such file or directory: '1.fasta'
咋办?

追答

for b in files:
c=open(os.path.join(a,b))
....
不好意思,之前的代码没有考虑你执行的目录和要处理的目录不一致的问题。

温馨提示:答案为网友推荐,仅供参考