-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmycmp.py
More file actions
41 lines (31 loc) · 988 Bytes
/
mycmp.py
File metadata and controls
41 lines (31 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import sys
import filecmp
class MyDirCmp(filecmp.dircmp):
def phase3(self): # Find out differences between common files
xx = filecmp.cmpfiles(self.left, self.right, self.common_files, shallow=False)
self.same_files, self.diff_files, self.funny_files = xx
class FileDescriptor(object):
def __init__(self, file1=None, file2=None):
self.file1 = file1
self.file2 = file2
def get_files_recursive(d):
result = []
for dirpath, dirnames, filenames in os.walk(d):
for f in filenames:
fullpath = os.path.join(dirpath, f)
result.append(fullpath)
return result
left_files = get_files_recursive(dir1)
right_files = get_files_recursive(dir2)
left_only = []
identical = []
for f_left in left_files:
file_found = False
for f_right in right_files:
if filecmp.cmp(f_left, f_right, shallow=False):
identical.append(FileDescriptor(f_left, f_right))
file_found = True
filecmp.clear_cache()
if not file_found:
left_only.append(f_left)