Skip to content Skip to sidebar Skip to footer

Removing Path From A Zip File Using Python

I have a zip file that has a path. When I unzip the file using python and put it in my target folder, it then creates all of the files in the path inside my target folder. Target:

Solution 1:

How about reading file as binary and dump it? Need to deal cases where there is pre-existing file.

for name in zfile.namelist():

    fname = os.path.join(zipdir, os.path.basename(name))
    fout = open(fname, 'wb')
    fout.write(zfile.read(name))

Post a Comment for "Removing Path From A Zip File Using Python"