简体   繁体   中英

How can I extract a zip archive that contains a forbidden file name on Windows using Python?

I've been trying to write a Python program to assist with installing Minecraft mods. This requires extracting an obfuscated JAR file and adding some new classes. However, one of the obfuscated files is called aux.class . Any file named aux , no matter what extension, is forbidden on Windows due to it being a DOS device name. I need to figure out some way to extract this file and then rearchive it while keeping Windows happy. How can I do this?

you don't have to write the file, or extract it. you can use

toolzip = zipfile.ZipFile(myzipfile,  'r')
names = toolzip.namelist()
for n in names:
    data = toolzip.read(n)
    # do something with data

including writing the data back to another zip.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM