how to delete hyphen in filename and add something to the name ? python
<p>i have a folder with a lot of files like that:</p>

<pre><code>2012-05-09.txt
2012-05-10.txt
2012-05-11.txt
etc. 
</code></pre>

<p>now i wanna delete the hyphen and add " _PHOTOS_LOG " that it looks in the end like this:</p>

<pre><code>20120509_PHOTOS_LOG.txt
20120510_PHOTOS_LOG.txt
20120511_PHOTOS_LOG.txt
etc.
</code></pre>

<p>How to do ? </p>

<p>thats the code now: </p>

<pre><code>//updated the code, now its working 

import os
import glob
import os.path
import sys


src = 'D:\\testing/hyphen1'

src = r'D:\testing\test'

for fn in os.listdir(src):
    new_filename = fn.replace('-','').replace('.txt', '_PHOTOS_LOG.txt')
    fn = os.path.join(src, fn)
    new_filename = os.path.join(src, new_filename)
    try:
        os.rename(fn, new_filename)
    except (WindowsError, OSError):
        print 'Error renaming "%s" to "%s"' % (fn, new_filename)
        print sys.exc_info()[1]
</code></pre>
