- #!/usr/bin/python
- # -*- coding:utf-8 -*-
- #在这几个文件夹中,在同名文件之间,若发现有相同的“行”内容,则全部删除不保留,在原始文件中只保留不重复的内容。
-
- import os
-
-
- dic = {}
- def uniq(dirPath='.'):
-
- for i in os.listdir(dirPath):
- with open('%s\%s' % (dirPath, i), 'r+') as file:
- print("%s\n%s\n%s" % ('{:*<30}'.format(''), i, '{:*<30}'.format('')))
- f = file.readlines()
- file.seek(0)
- file.truncate()
- for line in f:
- if i not in dic:
- dic[i] = []
- if line not in dic[i]:
- dic[i].append(line)
- file.write(line)
- print(line)
-
- #multiple source folders
- for i in [r'D:\1',r'D:\2']:
- uniq(i)
复制代码
|