-1

I am trying to open a file with a zip file in python and copy it somewhere else. How do I go about handling the ZIP file open? I can copy and move files fine, it is just getting into the zip file.

File PATH: t:/Test/step1/step2/test.zip/FIL

I have looked at Zipfile docs, but I just can't get this to work right.

zipfile.ZipFile('file_path', 'r')

Trying_hard
  • 8,931
  • 29
  • 62
  • 85
  • 2
    *"... but I just can't get this to work right."* -- if you can show what you tried someone can point you down the right track. – Shawn Chin May 10 '13 at 14:25
  • 1
    refer to http://stackoverflow.com/questions/4917284/extract-files-from-zip-without-keeping-the-structure-using-python-zipfile for how to open a zip file using python – Rachel Gallen May 10 '13 at 14:26
  • you may also find this helpful http://pymotw.com/2/zipfile/ – Rachel Gallen May 10 '13 at 14:27

1 Answers1

0

As I understand your question, you want to extract a single file from a ZIP archive. Which you do like this:

import zipfile
with zipfile.ZipFile('example.zip', 'r') as zf:
    zf.extract(filename)

If you want to extract the file to a different directory, specify that in the path parameter of extract().

zf.extract(filename, path)
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490