unzip zip files

DataSmash rdh at new.rr.com
Mon May 15 09:41:57 EDT 2006


Thanks!
I ended up using the "-d" parameter.
I did try the zipfile module but I couldn't figure it out, nor could I
find any examples using it.
I also didn't have any luck changing the working dircectory and making
it work.

import subprocess, os

# Get all the zip files in the current directory.
for zip in os.listdir(''):
    if zip.endswith(".zip"):

        # Remove the first 3 and the last 4 characters
        # e.g. usa12345.zip becomes 12345
        zipBase = zip[3:-4]

        # Make directory for unzipping
        os.mkdir(zipBase)

        # Make system call "unzip"
        print "\n unzip -d", zipBase, zip
        subprocess.Popen(["unzip", "-d", zipBase, zip]).wait()




More information about the Python-list mailing list