Please tell me why this code fails. I am new and I don't understand why
my formatting of my zip arguments is incorrect. Since I am unsure how
to communicate best so I will show the code, the error message, and
what I believe is happening.<br><br><pre class="prettyprint"><code><span class="com"><font style="font-family: courier new,monospace;" size="2">#!c:\python30<br># Filename: backup_ver5.py<br><br>import os<br>import time<br>
import zipfile<br><br><br>source = r&#39;C:\Documents and Settings\Benjamin Serrato\My Documents\python\backup_list&#39;<br><br>target_dir = r&#39;C:\Documents and Settings\Benjamin Serrato\My Documents\python\backup_dir&#39;<br>
<br>today = target_dir + os.sep + time.strftime(&#39;%Y%m%d&#39;) <br><br>now = time.strftime(&#39;%H%M%S&#39;)<br><br>comment = input(&#39;Enter a comment --&gt; &#39;)<br><br>if len(comment) == 0:<br>        target = today + os.sep + now + &#39;.zip&#39;<br>
else:<br>        target = today + os.sep + now + &#39;_&#39; + \<br>        comment.replace(&#39; &#39;, &#39;_&#39;) + &#39;.zip&#39;<br><br>if not os.path.exists(today):<br>        os.mkdir(today)<br>        print(&#39;Successfully created directory&#39;, today)<br>
<br><br>print(target)<br>print(source)<br>zip_command = zipfile.ZipFile(target, &#39;w&#39;).write(source)<br><br>if os.system(zip_command) == 0:<br>        print(&#39;Successful backup to&#39;, target)<br>else:<br>        print(&#39;Backup FAILED&#39;)</font><br>
</span><span class="pun"></span><span class="pln"><br></span></code></pre>I receive this error message:<br><br><span style="font-family: courier new,monospace;">Enter a comment --&gt;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">C:\Documents and Settings\Benjamin Serrato\My Documents\python\backup_dir\200904</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">05\154956.zip</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">C:\Documents and Settings\Benjamin Serrato\My Documents\python\backup_list</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Traceback (most recent call last):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">  File &quot;C:\Documents and Settings\Benjamin Serrato\My Documents\python\backup_ve</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">r5.py&quot;, line 32, in &lt;module&gt;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    zip_command = zipfile.ZipFile(target, &#39;w&#39;).write(source)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  File &quot;c:\python30\lib\zipfile.py&quot;, line 1031, in write</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    fp = io.open(filename, &quot;rb&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  File &quot;C:\Python30\lib\io.py&quot;, line 222, in open</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    closefd)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  File &quot;C:\Python30\lib\io.py&quot;, line 615, in __init__</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    _fileio._FileIO.__init__(self, name, mode, closefd)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">IOError: [Errno 13] Permission denied: &#39;C:\\Documents and Settings\\Benjamin Ser</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">rato\\My Documents\\python\\backup_list&#39;</span><br><br><p>The two print tests before <code>zip_command</code> is assigned tell  me that the two strings are being passed to <code>zipfile.ZipFile()</code> correctly.  The traceback tells me I am not calling <code>zipfile.ZipFile()</code> correctly.  The error in <code>__init__</code>
makes me more sure of this. Last, the problem seems to be that I am
causing my path string to have double backslashes. I can&#39;t follow why
the IOError shows that.</p>

<p>I used <a href="http://docs.python.org/dev/3.0/library/zipfile.html" rel="nofollow">this site</a> to figure out how to use <code>zipfile</code>.  <code>zipfile</code>
is a class, I import it at the start of the program then I use it and
its primary method. I pass the file I would like to write to <code>zipfile.ZipFile(&#39;file to write&#39;, &#39;mode&#39;)</code>
and set the program to open an object set to be writable. Then the
command writes the file to the destination folder with a sub-method
like so, <code>&quot;&quot;.zipfile(&#39;files to write&#39;)</code>.</p>

<p>Where am I going wrong?</p><br>