完善页面细节
This commit is contained in:
59
find_all_encodings.py
Normal file
59
find_all_encodings.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
|
||||
def detect_file_info(file_path):
|
||||
try:
|
||||
with open(file_path, 'rb') as f:
|
||||
data = f.read()
|
||||
|
||||
# Check for UTF-8-SIG (BOM)
|
||||
if data.startswith(b'\xef\xbb\xbf'):
|
||||
return "UTF-8 with BOM"
|
||||
|
||||
# Check for normal UTF-8
|
||||
try:
|
||||
data.decode('utf-8')
|
||||
return "UTF-8"
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
# Check GBK
|
||||
try:
|
||||
data.decode('gbk')
|
||||
return "GBK"
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
# Check UTF-16
|
||||
try:
|
||||
data.decode('utf-16')
|
||||
return "UTF-16"
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
return "Unknown"
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
|
||||
extensions = ('.uvue', '.uts', '.vue', '.json', '.js', '.ts', '.scss', '.md', '.txt', '.ps1', '.bat', '.sh')
|
||||
root_dir = r'd:\骅锋\mall'
|
||||
|
||||
results = []
|
||||
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):
|
||||
path = os.path.join(root, file)
|
||||
enc = detect_file_info(path)
|
||||
if enc not in ("UTF-8", "UTF-8 with BOM"):
|
||||
results.append((path, enc))
|
||||
|
||||
if not results:
|
||||
print("No non-UTF8 files found.")
|
||||
else:
|
||||
print(f"{'Encoding':<20} | {'Path'}")
|
||||
print("-" * 100)
|
||||
for path, enc in results:
|
||||
print(f"{enc:<20} | {path}")
|
||||
|
||||
print(f"\nScan complete. Total non-UTF8 found: {len(results)}")
|
||||
Reference in New Issue
Block a user