import sys, os
from pathlib import Path

# Number of first bytes from a file that we are compare
number_of_bytes = 1024

# Path that we will examine
p = Path(r'e:\\')

# Create pattern of \x00
pattern = b''
for _i in range(number_of_bytes):
    pattern += b'\x00'

# Report files
filename_null_character = str("NullCharacterFiles.txt")
filename_not_null_character = str("NotNullCharacterFiles.txt")
filename_exceptions = str("ExceptionFiles.txt")

# Remember exception files and print it at the end of the process
list_of_exception_files = []

# Delete files, if they are exists to begin fresh files
if os.path.isfile(filename_null_character):
    os.remove(filename_null_character)

if os.path.isfile(filename_not_null_character):
    os.remove(filename_not_null_character)

# Traverse path
for file_name in p.glob('**/*'):

    # Don't compare symbolic links
    if os.path.islink(file_name):
        continue

    # Don't check direcories (doesn't have a "size")
    if os.path.isdir(file_name):
        print(str("Pruefe Verzeichnis: ") + str(file_name))
        continue

    try:
        with open(file_name, 'rb') as f:

            first_bytes_block = f.read(number_of_bytes)

            # Compare if the first block of the file matchs the pattern
            if first_bytes_block == pattern:
                with open(filename_null_character, "a", encoding ="utf-8") as file_object:
                    # Append 'hello' at the end of file
                    line = str(file_name) + "\n"
                    file_object.write(line)
                    print(str('Startblock besteht ausschliesslich aus \\x00: ') + str(file_name))
            else:
                with open(filename_not_null_character, "a", encoding ="utf-8") as file_object:
                    line = str(file_name) + "\n"
                    file_object.write(line)
                    #print(str('Startblock besteht ausschliesslich nicht nur aus \\x00: ') + str(file_name))
    except:
        exception_string = str("Ausnahme: ") + str(file_name).encode('utf-8', 'replace').decode()
        list_of_exception_files.append(exception_string)
        with open(filename_exceptions, "a", encoding ="utf-8") as file_object:
                line = str(file_name.as_uri) + "\n"
                file_object.write(line)
        #print(exception_string)


print("===============================================")
print(*list_of_exception_files, sep = "\n") 
print("===============================================")
print("Prozess durchgelaufen")
print(str(filename_null_character) + ", " + str(filename_exceptions) + " und " + str(filename_not_null_character) + " je nach Fall erstellt.")