From: Paul van Delst Date: 2006-08-02T06:05:08+09:00 Subject: Re: cp * except .svn directories Mark Woodward wrote: > Hi all, > > sorry if this is a repost! Don't know if it's Pan or my ISP but there's > some weirdness going on ATM! > > What I'd like to be able to do is write a script that can copy all > files/directories from a subversion repository except .svn directories. > > This is the best I can come up with from the command line (be gentle ;-)): > > 1. cd to repos dir > 1. tar --exclude=".svn" -cvf foo.tar * > 2. mv foo.tar /path/to/new > 2. cd /path/to/new > 3. tar -xvf foo.tar > > It works but I'm hoping there's a way to do this in a ruby script. If possible > I'd like to be able to input "/path/to/new". > > So if I'm in the repos dir: > > cp_wo_svn.rb > "to where?": /var/www > "done!" I think Julian Tarkh's solution is the easiest. But if you must do it in ruby, you can use the Find module. Paraphrased from the Ruby Cookbook (pg216): require 'find' Find.find('./') do |path| Find.prune if File.basename(path) == '.svn' puts path end In irb: irb(main):001:0> require 'find' => true irb(main):002:0> Find.find('./') do |path| irb(main):003:1* Find.prune if File.basename(path) == '.svn' irb(main):004:1> puts path irb(main):005:1> end ./ ./branches ./tags ./trunk ./trunk/fdefmod ./trunk/fdefmod/test ./trunk/fdefmod/test/test.type ./trunk/fdefmod/test/test_ftypedef.rb ./trunk/fdefmod/test/test_fdefmod.rb ./trunk/fdefmod/test/ftypedef.rb ./trunk/fdefmod/lib ./trunk/fdefmod/lib/~fdefmod.rb ./trunk/fdefmod/lib/ftypedef.rb ./trunk/fdefmod/lib/fdefmod.rb ./trunk/learningcurve ./trunk/learningcurve/test ./trunk/learningcurve/lib ./trunk/learningcurve/lib/tconvert.rb ./trunk/util ./trunk/util/test ./trunk/util/lib ./trunk/util/lib/eh2mh.rb Without the Find.prune, you'll get everything: irb(main):001:0> require 'find' => true irb(main):002:0> Find.find('./') do |path| irb(main):003:1* puts path irb(main):004:1> end ./ ./.svn ./.svn/tmp ./.svn/tmp/props ./.svn/tmp/wcprops ./.svn/tmp/text-base ./.svn/tmp/prop-base ./.svn/props ./.svn/format ./.svn/wcprops ./.svn/text-base ./.svn/prop-base ./.svn/empty-file ./.svn/entries ./.svn/README.txt ./branches ./branches/.svn ./branches/.svn/tmp ./branches/.svn/tmp/props .etc......lotsa .svn stuff...... cheers, paulv -- Paul van Delst Ride lots. CIMSS @ NOAA/NCEP/EMC Eddy Merckx Ph: (301)763-8000 x7748 Fax:(301)763-8545