-
-
Save yuhangch/15c015df98a4fe47e0435534cf6285ad to your computer and use it in GitHub Desktop.
Python Zipfile 中文文件名乱码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zipfile import ZipFile | |
from pathlib import Path | |
target_directory = "." | |
with ZipFile(src, 'r') as f: | |
for file_name in f.namelist(): | |
file_name = f.extract(file_name, path=target_directory) | |
try: | |
fn2 = file_name.encode('cp437').decode('gbk') | |
except: | |
fn2 = file_name.encode('utf-8').decode('utf-8') | |
extracted_path = Path(file_name) | |
extracted_path.rename(fn2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment