[Tutor] copy zip file from source folder to destination and unzip all files within destination
Kent Johnson
kent37 at tds.net
Fri Nov 20 13:11:59 CET 2009
On Fri, Nov 20, 2009 at 1:54 AM, MARCUS NG <markersng at gmail.com> wrote:
> Hey all,
> I have been searching online for ways to copy a zip file to a destination
> and extract the zip file with python.
> Currently nothing works due to my limited understanding.
> I am wondering if my syntax is wrong or am I missing anything?
You don't say how it fails but you should at least escape the \ in the
paths as \\ or use raw strings (r'C:\Users...')
The \char codes are escape codes so your paths are not correct.
Kent
> the code is as such. also if there is a better code, I am definitely open to
> it. If it is good, can you also explain steps?
> ###########
>
> import shutil, zipfile
> shutil.copyfile('C:\Users\blueman\Desktop\myTest1.0.zip',
> 'C:\Users\blueman\Desktop\allFiles')
>
> zipfilepath='C:\Users\blueman\Desktop\allFiles\myTest1.0.zip'
> extractiondir='C:\Users\blueman\Desktop\allFiles\test'
>
> def extract(zipfilepath, extractiondir):
> zip = zipfile(zipfilepath)
> zip.extractall(path=extractiondir)
> print 'it works'
>
> extract()
>
> ###########
> thank you so much for your time and help in advance!!!
>
>
> ,
> Marcus
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list