import os

dirs = list()

debug_level = 3

dirs.append(input("Scan directory: "))

while len(dirs)>0:
    print("Searching directory "+dirs[0]+".")
    d = os.scandir(dirs.pop(0))
    for i in d:
        if i.is_dir():
            if(debug_level>1):
                try:
                    print("Found directory "+i.name+". Adding to list.")
                except UnicodeEncodeError:
                    print("Found directory with non-unicode name. Adding to list.")
            dirs.append(i.path)
            continue
        if i.name.startswith("._"):
            if(debug_level>0):
                try:
                    print("Found hidden file "+i.path+". Removing.")
                except UnicodeEncodeError:
                    print("Found hidden file with non-unicode name. Removing.")
            os.remove(i.path)
            continue
        if(debug_level>2):
            try:
                print("Found file "+i.path+". Continuing.")
            except UnicodeEncodeError:
                print("Found file with non-unicode name. Continuing.")