擅长:python、mysql、java
<p>更全面地理解hughdbrown的答案。此代码可用于删除任何特定字符或字符集。</p>
<pre><code>import os
paths = (os.path.join(root, filename)
for root, _, filenames in os.walk('C:\FolderName')
for filename in filenames)
for path in paths:
# the '#' in the example below will be replaced by the '-' in the filenames in the directory
newname = path.replace('#', '-')
if newname != path:
os.rename(path, newname)
</code></pre>