#coding=utf-8
import os
#使用递归去解决
def merge(folder_path):
for f in os.listdir(folder_path):
file_path = os.path.join(folder_path,f)
if os.path.isdir(file_path):
merge(file_path)
else:
merge_file = open('/tmp/merge_file','ab+')
content = open(file_path,'r').read()
merge_file.write(content)
merge_file.close()
print file_path
merge('/home/aspire/tmp/test')
import os
#使用递归去解决
def merge(folder_path):
for f in os.listdir(folder_path):
file_path = os.path.join(folder_path,f)
if os.path.isdir(file_path):
merge(file_path)
else:
merge_file = open('/tmp/merge_file','ab+')
content = open(file_path,'r').read()
merge_file.write(content)
merge_file.close()
print file_path
merge('/home/aspire/tmp/test')
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10972173/viewspace-2125616/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10972173/viewspace-2125616/