title: wget: How do I specify both --directory-prefix AND --output-document
body: <p>When I use either the <code>-P</code> or <code>-O</code> alone with <code>wget</code>, everything works as advertised. </p>
  
  <pre><code>$: wget -P "test" http://www.google.com/intl/en_com/images/srpr/logo3w.png
  Saving to: `test/logo3w.png'  
  </code></pre>
  
  <p>.</p>
  
  <pre><code>$: wget -O "google.png" http://www.google.com/intl/en_com/images/srpr/logo3w.png
  2012-01-23 21:47:33 (1.20 MB/s) - `google.png' saved [7007/7007]
  </code></pre>
  
  <p>However, combining the two causes <code>wget</code> to ignore <code>-P</code>.</p>
  
  <pre><code>$: wget -P "test" -O "google.png" http://www.google.com/intl/en_com/images/srpr/logo3w.png
  2012-01-23 21:47:51 (5.87 MB/s) - `google.png' saved [7007/7007]
  </code></pre>
  
  <p>I've set a variable for both the directory (generated by the last chunk of the URL) and the filename (generated through a counting loop) such that <code>http://www.google.com/aaa/bbb/ccc</code> yields <code>file</code> = <code>/directory/filename</code>, or, for item 1, <code>/ccc/000.jpg</code></p>
  
  <p>When substituting this in to the code:<br>
  <code>Popen(['wget', '-O', file, theImg], stdout=PIPE, stderr=STDOUT)</code><br>
  <code>wget</code> silently fails (on each iteration of the loop).</p>
  
  <p>When I turn on debugging <code>-d</code> and logging <code>-a log.log</code>, each iteration prints<br>
  <code>DEBUG output created by Wget 1.13.4 on darwin10.8.0.</code></p>
  
  <p>When I remove the <code>-O</code> and <code>file</code>, the operation proceeds normally.</p>
  
  <p>My question is:
  Is there a way to<br>
  A) Specify both <code>-P</code> <em>AND</em> <code>-O</code> in <code>wget</code> (preferred) or<br>
  B) Insert a string to <code>-O</code> containing <code>/</code>-characters that doesn't cause it to fail?</p>
  
  <p>Any help would be appreciated.</p>