<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16735" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=858070018-28102008><FONT face=Arial size=2>Hey 
Python-ers,</FONT></SPAN></DIV>
<DIV><SPAN class=858070018-28102008><FONT face=Arial size=2>I apologize if this 
is covered in the archives; I think I saw one instance of it but I couldn't get 
the solution to work out.</FONT></SPAN></DIV>
<DIV><SPAN class=858070018-28102008><FONT face=Arial size=2>I'm working on 
zipping an entire directory to one zip file. I can zip a flat group of files, 
but when my code encounters a hierarchy of folders, for some reason it starts to 
zip everything on my desktop (instead of everything inside one folder directory 
on desktop).  Then it goes into an infinite loop and 
barfs.</FONT></SPAN></DIV>
<DIV><SPAN class=858070018-28102008><FONT face=Arial 
size=2></FONT></SPAN> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=858070018-28102008>Here's what I have 
so far:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=858070018-28102008></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=858070018-28102008>import 
zipfile<BR>import glob, os</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=858070018-28102008>def 
main():</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=858070018-28102008>    
directory = "test\*"<BR>    
(success,filename)=createZipFile(directory);<BR>    if success == 
1:<BR>        print "Operation completed. All 
files written to zip."<BR>    
else:<BR>        print "Operation 
failed."</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=858070018-28102008>def 
createZipFile(directory):<BR>    zippedHelp = 
zipfile.ZipFile("help.zip", "w" ) </SPAN></FONT></DIV><FONT><SPAN 
class=858070018-28102008>
<DIV><BR><FONT face=Arial size=2>    for entity in 
directory:<BR>        if os.<SPAN 
class=858070018-28102008>path.isfile</SPAN>(entity):<BR>            
zippedHelp.write(entity,os.path.basename(entity),zipfile.ZIP_DEFLATED)<BR>        
else:<BR>            
addFolderToZip(zippedHelp,entity)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>    
zippedHelp.close()<BR>    return (1,zippedHelp)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><BR><FONT face=Arial size=2>def 
addFolderToZip(zippedHelp,folder):</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>    for file in 
folder:<BR>            if 
os.path.isfile(file):<BR>                
zippedHelp.write(file, os.path.basename(file), 
zipfile.ZIP_DEFLATED)<BR>            
elif 
os.path.isdir(file):<BR>                
addFolderToZip(zippedHelp,file)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><BR><FONT face=Arial size=2>main()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><SPAN class=858070018-28102008><FONT face=Arial size=2>Thanks for any 
help!! :)</FONT></SPAN></DIV>
<DIV><SPAN class=858070018-28102008><FONT face=Arial 
size=2>Callie</FONT></SPAN></SPAN></FONT></DIV></BODY></HTML>