views:

1084

answers:

5

I need to change the capitalization of a set of files in a subversion working copy, like so:

svn mv test.txt Test.txt
svn mv test2.txt Test2.txt
svn mv testn.txt Testn.txt
...
svn commit -m "caps"

How can I automate this process? Standard linux install tools available.

A: 

I typically do this by redirecting the 'ls' output to a file, using vim macros to massage each filename into the command line I want, then execute the file as a shell script. It's crude but effective.

Andrew
+1  A: 

If you have a decent install you should have python, give this a try:

#!/usr/bin/python
from os import rename, listdir
path = "/path/to/folder"
try:
    dirList = listdir(path)
except:
    print 'There was an error while trying to access the directory: '+path
for name in dirList:
    try:
     rename(path+'\\'+name, path+'\\'+name.upper())
    except:
     print 'Process failed for file: '+name
Unkwntech
name.capitalize(), not upper()
Federico Ramponi
that will depend on what is wanted, if he wants "Filename" then yes you are correct however I assumed "FILENAME" was wanted in which case I am correct.
Unkwntech
+8  A: 

ls | awk '{system("svn mv " $0 " " toupper(substr($0,1,1)) substr($0,2))}'

obviously, other scripting languages will work just as well. awk has the advantage that it it ubiquitous.

ejgottl
Perfect, just the one liner I was looking for!
Ilia Jerebtsov
great indeed. let's upvote
Federico Ramponi
A: 

I don't think theres an easy way to do it with bash/sed/tr/find.

I'd make a Ruby/Perl script that does the renaming.

 #!/usr/bin/ruby 
 #  Upcase.rb 
 ARGV.each{ |i|
  newname = i.gsub(/(^.|\s.)/{ |x| x.upcase }
  `svn mv "#{i}" "#{newname}" `
 }

Then just do

 ./Upcase.rb foo.txt test.txt test2.txt foo/bar/test.txt

or if you want to do a whole dir

 find ./ -exec ./Upcase.rb {} +
Kent Fredric
A: 

Please note that this change breaks existing workingcopies on Windows and Mac systems, as they can't handle case only renames.

Bert Huijben