Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import sys
- if len(sys.argv) < 2:
- print("must specify a folder to run against for rename")
- sys.exit()
- #lists so they maintain order
- src = []
- dest = []
- for root, dirs, files in os.walk(sys.argv[1]):
- #print("root is %s" % root)
- for directory in dirs:
- #print("directory is %s" % directory)
- #remove _ from folder name
- folder = directory.replace('_', '')
- #add 'g' to the beginning of the folder name
- folder = 'g' + folder
- #print("folder name would be: %s" % folder)
- src.append(os.path.join(root, directory))
- dest.append(os.path.join(root, folder))
- #rename the folders.
- #Had to build a list first otherwise it will not properly continue into sub directories after rename
- #we start with the most sub folder so that when we rename it, the other paths aren't broken
- for i in reversed(range(0, len(src))):
- print("renaming %s to %s" %(src[i], dest[i]))
- os.rename(src[i], dest[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement