diff --git a/search_email.py b/search_email.py new file mode 100644 index 0000000..792cfa3 --- /dev/null +++ b/search_email.py @@ -0,0 +1,38 @@ +import os + +def search_email(directory, email): + if not os.path.isdir(directory): + print(f"Invalid directory: {directory}") + return + + print(f"Searching in directory: {directory}") + for root, dirs, files in os.walk(directory): + print(f"Checking directory: {root}") + for file in files: + file_path = os.path.join(root, file) + print(f"Checking file: {file_path}") + try: + with open(file_path, 'r', encoding='utf-8') as f: + content = f.read() + if email in content: + print(f"Found '{email}' in: {file_path}") + except UnicodeDecodeError: + print(f"Could not read file {file_path} with utf-8 encoding. Trying with 'latin-1'.") + try: + with open(file_path, 'r', encoding='latin-1') as f: + content = f.read() + if email in content: + print(f"Found '{email}' in: {file_path}") + except Exception as e: + print(f"Could not read file {file_path} with latin-1 encoding: {e}") + except FileNotFoundError: + print(f"File not found: {file_path}") + except IsADirectoryError: + print(f"Expected a file but found a directory: {file_path}") + except Exception as e: + print(f"Could not read file {file_path}: {e}") + +if __name__ == "__main__": + directory = "/Users/el_diablo_blanco/Documents/GitHub/nxshell" + email = "kristenmariet@yahoo.com" + search_email(directory, email)