def dir_hash(dir_name):
 if (not os.path.isdir(dir_name)):
  raise TypeError('{} is not a directory.'.format(dir_name))
 md5 = hashlib.md5()
 for (root, dirs, files) in os.walk(dir_name, topdown=True):
  if (not re.search('/\\.', root)):
   for f in files:
    if ((not f.startswith('.')) and (not re.search('/\\.', f))):
     file_name = os.path.join(root, f)
     md5.update(hashlib.md5(file_name).hexdigest())
     data = open(file_name, 'rb').read()
     md5.update(hashlib.md5(data).hexdigest())
 return md5.hexdigest()

def dir_hash ( dir_name ) : if ( not os . path . isdir ( dir_name ) ) : raise TypeError ( '{} is not a directory.' . format ( dir_name ) ) md5 = hashlib . md5 ( ) for ( root , dirs , files ) in os . walk ( dir_name , topdown = True ) : if ( not re . search ( '/\\.' , root ) ) : for f in files : if ( ( not f . startswith ( '.' ) ) and ( not re . search ( '/\\.' , f ) ) ) : file_name = os . path . join ( root , f ) md5 . update ( hashlib . md5 ( file_name ) . hexdigest ( ) ) data = open ( file_name , 'rb' ) . read ( ) md5 . update ( hashlib . md5 ( data ) . hexdigest ( ) ) return md5 . hexdigest ( )
return a hash for the files in a directory tree .