Quick python script to rename directories AND files (recursively) in SVN repositories that have spaces in them. So next time somebody checks in a file pile containing spaces, I run this, and commit. End of problem. Inspired by https://gist.github.com/kranthilakum/7536042, which renames only immediate files, via os.rename(). Hope it helps someone…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
import time | |
import subprocess | |
def space2_(directory): | |
for filename in os.listdir(directory): # parse through file list in the current directory | |
#print "checking %s" % filename | |
if filename.find(".svn") >= 0: | |
continue | |
if filename.find(" ") >= 0: # if a space is found | |
newfilename = filename.replace(" ","_") # convert spaces to underscores | |
args = (['svn','mv',filename, newfilename]) # rename the file via svn mv | |
subprocess.call(args, shell=False) | |
filename = newfilename | |
if os.path.isdir(filename): | |
os.chdir(filename) | |
space2_(".") | |
os.chdir("..") | |
space2_('.') # parse through file list in the current directory |
You're welcome, and thank you for letting me know. That's what this free-software/sharing thing is all about. ☮️
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for the script. It made one of my jobs easy, otherwise which it would have been a nightmare for me.