title: Python: How to replace dashes in filenames?
body: <p>The question is related to the <a href="https://stackoverflow.com/questions/641985/rename-files-python-jython/642295#642295">answer</a> about renaming files recursively.</p>
  
  <p>The code, changed to replace dashes, does not work with cases such as:</p>
  
  <pre><code>./Beginners Tools/Hello's -Trojans-/bif43243
  ./Linux/Nux Col - 1 Works (TEX &amp; Pdf) - T'eouhsoe &amp; More (33323 - 34432)
  ./Git/peepcode-git-mov/c6_branch_merge.mov
  ./haskell/OS 2007 - T aoue
  ./B Sites for Get-Big
  </code></pre>
  
  <p>It worked with cases such as:</p>
  
  <pre><code>./oeu'oeu - X ee ls - Feb 2008.pdf
  </code></pre>
  
  <p>So I need to parse the data. How can I correctly replace dashes? </p>
  
  <p><strong>[Details]</strong></p>
  
  <p>The code is from the link, but changed to replace "-":</p>
  
  <pre><code>import os
  for dirpath, dirs, files in os.walk(your_path):
      for filename in files:
          if '&amp;' in filename:
              os.rename(
                  os.path.join(dirpath, filename),
                  os.path.join(dirpath, filename.replace('-', '_'))
              )
  </code></pre>
  
  <p>The Python did not replace every dash. I think it is because the names contains special signs that stopped the script earlier. So I encountered errors in archieving:</p>
  
  <pre><code>tar cvzf sed_backup.tar.gz `find documents | sed  s/\.*/\'\&amp;\'/`
  tar: rojans-: Cannot stat: No such file or directory
  tar: Error is not recoverable: exiting now
  </code></pre>
  
  <p>Because of the signs " ' " and " - " still left in the names, the tar-command interpret " ' " as an end for the find-command and " - " as an option sign in the path "./Beginners Tools/Hello's -Trojans-/bif43243"</p>