import sys input_path = '/Users/bartels-rausch/Documents/GitLab/functionsMatlab/beamtime/nappFileList.m' output_path = '/Users/bartels-rausch/Documents/GitLab/functionsMatlab/beamtime/nappFileList_clean.m' try: with open(input_path, 'rb') as f: content = f.read() # Try decoding as utf-8, replace errors text = content.decode('utf-8', errors='replace') with open(output_path, 'w', encoding='utf-8') as f: f.write(text) print(f"Successfully cleaned file to {output_path}") except Exception as e: print(f"Error: {e}")