Files
medical-mall/final_admin_check.py
2026-02-25 11:39:54 +08:00

39 lines
1.2 KiB
Python

import os
root_dir = r'pages/mall/admin'
extensions = ('.uvue', '.uts', '.vue', '.json', '.js', '.ts', '.scss', '.md', '.txt', '.ps1', '.bat', '.sh')
print(f"Checking every text file in {os.path.abspath(root_dir)} recursively...")
found_count = 0
for root, dirs, files in os.walk(root_dir):
for file in files:
if file.lower().endswith(extensions):
path = os.path.join(root, file)
try:
with open(path, 'rb') as f:
data = f.read()
# Try UTF-8
try:
data.decode('utf-8')
# If success, skip
continue
except UnicodeDecodeError:
# Non-UTF8!
try:
data.decode('gbk')
enc = 'GBK'
except:
enc = 'Other non-UTF8'
print(f"{enc:<20} | {os.path.abspath(path)}")
found_count += 1
except Exception as e:
# print(f"Error {path}: {e}")
pass
if found_count == 0:
print("All scanned files are valid UTF-8.")
else:
print(f"\nFound {found_count} non-UTF-8 files.")