简体   繁体   English

如何在Windows上使用Python提取包含禁止文件名的zip存档?

[英]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. 我一直在尝试编写Python程序来协助安装Minecraft mod。 This requires extracting an obfuscated JAR file and adding some new classes. 这需要提取混淆的JAR文件并添加一些新类。 However, one of the obfuscated files is called aux.class . 但是,混淆文件之一称为aux.class Any file named aux , no matter what extension, is forbidden on Windows due to it being a DOS device name. Windows中禁止使用任何名为aux文件(无论扩展名如何),因为该文件是DOS设备名称。 I need to figure out some way to extract this file and then rearchive it while keeping Windows happy. 我需要找出一些方法来提取此文件,然后在使Windows满意的同时对其进行归档。 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. 包括将数据写回到另一个zip。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 CSV 文件附加到 Python 中的现有 zip 存档? - How can I append a CSV file to an existing zip archive in Python? Zip包含一个档案文件夹,如何使用Python获取档案中每个zip的注释? - Zip contains a folder of archives, how to get the comments of each zip in the archive using Python? 使用Python,获取zip存档中的文件名 - Using Python, getting the name of files in a zip archive 如何在 Python 中仅列出 zip 存档中的文件夹? - How can i list only the folders in zip archive in Python? 如何使用 Python 将 zip 中的文本文件解压缩为 zip - How to extract the text file from zip into zip using Python python如何在zip存档中附加到文件 - python how to append to file in zip archive 如何在 python 中使用没有文件扩展名的 shutil.make_archive() 创建 zip 存档? - How to create zip archive using shutil.make_archive() without a file extension in python? 如何在 Python 中提取使用 PKWARE SecureZip 压缩的受密码保护的 zip 文件? (视窗 10) - How to extract a password protected zip file that is zipped using PKWARE SecureZip in Python? (Windows 10) python和Windows文件系统:检查zip归档文件中是否存在文件名 - python and windows file systems : check filename exists inside a zip archive 如何在python中提取带有dat扩展名的文件名? - How can I extract a file name with dat extension in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM