import os def check_encoding(file_path): try: with open(file_path, 'rb') as f: content = f.read() # Check UTF-8 try: content.decode('utf-8') return "UTF-8", False except UnicodeDecodeError: pass # Check GBK try: content.decode('gbk') return "GBK/GB2312", True except UnicodeDecodeError: pass # Check UTF-16 try: content.decode('utf-16') return "UTF-16", True except UnicodeDecodeError: pass return "Unknown/Other", True except Exception as e: return f"Error ({str(e)})", False extensions = ('.uvue', '.uts', '.vue', '.json', '.js', '.ts', '.scss', '.md', '.txt', '.ps1', '.bat', '.sh') root_dir = r'd:\骅锋\mall' non_utf8_files = [] for root, dirs, files in os.walk(root_dir): if any(skip in root for skip in ['.git', 'node_modules', 'unpackage']): continue for file in files: if file.lower().endswith(extensions): file_path = os.path.join(root, file) encoding, is_not_utf8 = check_encoding(file_path) if is_not_utf8: non_utf8_files.append((file_path, encoding)) for path, enc in non_utf8_files: print(f"{enc: <15} | {path}") print(f"\nTotal non-UTF8 files found: {len(non_utf8_files)}")