测试文件夹d:\1,d:\2
同文件名不重复的数据输出到d:\3文件夹
Python 3.5 - import os
-
- dic = {}
- def extract(dirPath='.'):
-
- for i in os.listdir(dirPath):
- with open('%s\%s' % (dirPath, i), 'r') as file:
- for line in file:
- if i not in dic:
- dic[i] = []
- if line not in dic[i]:
- dic[i].append(line)
-
- def save(dirpath='.'):
- for i in dic:
- with open(r'%s\%s' % (dirpath, i), 'w') as file:
- file.writelines(dic[i])
-
- #multiple source folder
- for i in [r'D:\1',r'D:\2']:
- extract(i)
-
- #save folder
- save(r'D:\3')
- #print(dic)
复制代码
|