Ilmari Heikkinen
12/19/2004 3:38:00 AM
Hi,
On 19.12.2004, at 04:57, itsme213 wrote:
> I am doing
> FileUtils.cp_r( "source/.", "generated")
> to copy a directory tree.
>
> How can I prune out any sub_tree with /.svn/ ?
If you want a tree without the .svn dirs,
one way would be to remove the .svn subtrees afterwards with something
like
(these use *nix utils so if you need it to work in pure ruby, replace
finds with corresponding results = []; Find.find{|filename| if
filename.is_bad? then Find.prune else results << filename end })
subdirs = `find . -type d -name .svn`.split(/\n/) # or the Find.find
equivalent
subdirs.each{|sd| FileUtils.rm_r(sd)}
Or the hard way:
cd to source dir and
dirs = `find . -type d -false -name .svn`.split(/\n/)
files = `find . -type f`.split(/\n/).find_all{|f| dirs.include?
File.dirname(f)}
files.each{|f|
# f should be relative to source dir root
FileUtils.mkdir_p(File.join(target_dir, File.dirname(f)))
FileUtils.cp(f, File.join(target_dir, f))
}
(maybe there's yet another easier way, I don't know)
-Ilmari