import os

import md5

 

def hash_dirs(dir_name):

    file_list = []

    hash_list = []

    for file in os.listdir(dir_name):

        if os.path.isfile(os.path.join(dir_name, file)):

            file_list.append(file)

            hash = md5.new()

            f = open(os.path.join(dir_name, file),'rb')

            hash.update(f.read())

            f.close()

            hash_list.append(hash.hexdigest())

        elif os.path.isdir(os.path.join(dir_name, file)):

            print "Accessing directory:", os.path.join(dir_name, file)

            fl, hl = hash_dirs(os.path.join(dir_name, file))

            for i in fl:

                file_list.append(i)

            for i in hl:

                hash_list.append(i)

        else:

            pass

 

    return file_list, hash_list

 

if __name__ == '__main__':

    dir_name = (os.path.join('C:\\', 'SDS2_7.0', 'macro'))

    fl, hl = hash_dirs(dir_name)

    for i in range(len(fl)):

        print 'File: %-32s  Hash: %s' % (fl[i], hl[i])