Skip to content

Instantly share code, notes, and snippets.

@timbaileyjones
Last active June 17, 2021 15:04
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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…
#!/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
@VenkataPavan2494
Copy link

Thank you so much for the script. It made one of my jobs easy, otherwise which it would have been a nightmare for me.

@timbaileyjones
Copy link
Author

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