Beispiel #1
0
    def recursive_checksum_dir(self, csv_write, abspath, csv_filename):
        if csv_write:
            with open(f'{csv_filename}.csv', 'w+'):
                pass

        for root, subdir, files in os.walk(self.dirPath, topdown=True):
            for file in files:
                if abspath:
                    filePath = os.path.abspath(os.path.join(root, file))
                else:
                    filePath = (os.path.join(root, file))
                try:
                    output = gen_md5(filePath, self.buffer_size, abspath)
                    if csv_write:
                        functions.csv_writer(output, csv_filename)
                except PermissionError as e:
                    print(
                        f"Error; Could not hash {filePath} : Permission Error")
                    print(e)
        if csv_write:
            functions.format_csv(f'{csv_filename}.csv')
Beispiel #2
0
    def checksum_dir(self, csv_write, abspath, csv_filename):

        global ignoreListDef
        if self.ignoreFile:
            ignoreListDef = functions.format_ignore(self.ignorePath)
        if csv_write:
            with open(f'{csv_filename}.csv', 'w+'):
                pass

        for item in os.listdir(self.dirPath):
            hashCheckCondition = False
            if self.ignoreFile:
                try:
                    for ignoreItem in ignoreListDef:
                        if ignoreItem == item:
                            hashCheckCondition = True
                except TypeError:
                    pass

            if hashCheckCondition:
                continue
            if not os.path.isdir(item):
                if abspath:
                    filePath = os.path.abspath(os.path.join(
                        self.dirPath, item))
                else:
                    filePath = item
                try:
                    output = gen_md5(os.path.join(self.dirPath, item),
                                     self.buffer_size, abspath)
                    if csv_write:
                        functions.csv_writer(output, csv_filename)
                except PermissionError as e:
                    print(
                        f"Error; Could not hash {filePath} : Permission Error")
                    print(e)
        if csv_write:
            functions.format_csv(f'{csv_filename}.csv')