Python
12 Jul 2010
 
 
 
 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
def checkFiles(self):
'''check'''
n = hashlib.md5()
cat = self.txtCat.text() #нужный каталог
print(cat)
md5Log = self.txtSave.text() #путь к файлу со слепком
print(md5Log)
with open(md5Log, "r") as fh: #открываем лог
for root, dirs, files in os.walk(cat): #рекурсивно обходим каталог
if len(dirs):
pass
if len(files):
for file in files:
path = os.path.join(root, file)
with open(path, "rb") as fp: #открываем файл на чтение
n.update(fp.read()) #создаем хэш-объект
#n.update(fp.read().encode('koi8-r'))
print(path + " = " + n.hexdigest() + "\n")
for line in fh:
check = re.findall(file, line) #ищем в каждой строке ищем имя файла
#check = re.findall(file.encode('cp1251'), line)
print(check)
if check: #если есть вхождения
# if n.hexdigest()
# res = line.split('=')
if line.split('=')[1].strip() != n.hexdigest(): #проверяем, были ли изменения
print('file change')
else: print('file not change')
print(check)
print(line.split('=')[1].strip())
continue