How to delete a file in a zip folder in Python

Updated on technology 2024-03-28
10 answers
  1. Anonymous users2024-02-07

    Use. pyzipfile

    The method is rudimentary.

    It's put. The files in the zip archive, except for the files to be deleted, are read out one by one and saved to a new file. Finally, overwrite the old file with the new one.

    #coding=utf-8

    import

    zipfile

    import

    your_delet_file="The name of the file you want to delete"

    old_zipfile=''

    New files. new_zipfile='archve_'

    New files. zin

    old_zipfile,r')

    Read the object.

    new_zipfile,w')

    The object is written.

    foritem

    buffer

    your_delet_file):

    Cull the files you want to delete.

    buffer)

    Write the file to a new object.

    Overwrite the old file with the new file.

    old_zipfile)

  2. Anonymous users2024-02-06

    Using the pyzipfile method is rudimentary. It is to read the files in the zip archive one by one, except for the files to be deleted, and save them to a new file. Finally, overwrite the old file with the new one.

    # coding=utf-8

    import zipfile

    import

    your_delet_file="The name of the file you want to delete"

    old_zipfile=''New files.

    new_zipfile='archve_'new file zin = (old zipfile,'r') read object zout = (new zipfile,'w') is written to the object for item in:

    buffer =

    if (!= your delet file): Culling the files to be deleted.

    buffer) writes the file to a new object and overwrites the old file with the new file.

    old_zipfile)

    ps: **I haven't tested it yet... Please test it yourself. If you have any questions, ask them again.

  3. Anonymous users2024-02-05

    zipfile does not support Sun Zhiyu to delete the suspect except for the operation: see the paragraph.

  4. Anonymous users2024-02-04

    OS can be called

    Modules for example. import

    Deletes the specified file.

    Deletes the specified directory.

    Execute system commands.

    For example"rm) note that due to the manipulation of the file, note the permission to execute python scripts.

    Otherwise, the execution may fail.

  5. Anonymous users2024-02-03

    import zipfile,os

    l=['']

    z = 'new_', 'w',zp= '')

    srczip = "", "r"):

    for eachfile in :

    eachfilename = , eachfile))if eachfilename not in l:

    eachfilename))

    Unzip first, then create a new one, and then filter the files you don't want before adding.

  6. Anonymous users2024-02-02

    zip * can be said to be not a drop. *There is also a point missing from the front. When you run unzip, you will find a phenomenon, there is no recursion when compressing, so you can say that this backup is an error drop, I have made this mistake several times.

    Compress the current folder zip -r/ .* -r denotes recursion.

    Unzip unzip is not interpreted.

  7. Anonymous users2024-02-01

    Use the -d parameter of the zip command to delete specific files in the zip package.

    Example: For example, if there are three files containing code (directory) and now you want to delete the code directory, run the following command:

    zip -d _code

  8. Anonymous users2024-01-31

    No, it doesn't. Linux can't do that, you have to unzip it before you can delete it. +741345015

  9. Anonymous users2024-01-30

    Unpack? —> delete? - > save? - > compression? Or do you want to delete it without unzipping?

  10. Anonymous users2024-01-29

    To delete the subfiles in the zip package, perform the following steps:

    1. Double-click to open the zip archive;

    2. Right-click to select the file you want to delete;

    3. Click Delete to finish.

    The operation is as follows:

Related questions
10 answers2024-03-28

1. For example, the data in the figure below. The first 3 characters of each cell data are the same. >>>More

9 answers2024-03-28

First of all, you have to understand that there are only two possibilities for this kind of problem:1You didn't install this software properly; 2.Environment variables are not configured. >>>More

16 answers2024-03-28

** Rules for Free (Regular) Numbers:

1. 3 days after registration, the number that has not logged in and has not added friends may be **. >>>More

9 answers2024-03-28

This problem is not operated in linux, you delete linux, how to use your machine without a system? >>>More

22 answers2024-03-28

1. For blank pages caused by carriage returns, select and delete all carriage returns on blank pages. 2. Insert blank pages caused by page breaks, if the number is small, blackout and select "Page Breaks" at the bottom of the previous page, and press the delete key or backspace key to delete. If you have a lot of page breaks, you can replace them with the Find & Replace function. >>>More