|
发表于 2009-7-20 00:08:40
|
显示全部楼层
应该可以用一两句命令来完成,但我不会……
也可以用一些简单的脚本来完成:
- python space_rename.py music/
复制代码
- #!/usr/bin/env python
- # coding: utf8
- import os
- import sys
- if len(sys.argv) != 2:
- print 'Usage: ' + sys.argv[0] + ' [root folder]'
- exit()
- def rename(path):
- char_org = ' '
- char_new = '-'
- node = os.path.basename(path)
- path_new = os.path.join( os.path.dirname(path),
- node.replace(char_org, char_new) )
- if not os.path.exists(path_new):
- os.rename(path, path_new)
- print 'rename %s to %s' % (path, path_new)
- return path_new
- return path
- def main():
- cwd = os.path.realpath(sys.argv[1])
- queue = [cwd]
- while len(queue) > 0:
- dir = queue.pop()
- for node in os.listdir(dir):
- path = os.path.join(dir, node)
- if os.path.isfile(path):
- rename( path )
- elif os.path.isdir(path):
- queue.insert(0, rename(path) )
- main()
复制代码
注:本脚本未经测试 |
|