Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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 {} + 

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top