Filtering files while copying/moving.

O

Ola Bini

Hi,

I have the need to filter files, replacing in-place-tokens with
variables during the copy. I would like to be able to do something like
this:

FileUtils.filter_cp_r from_dir, to_dir, { "SERVER1" => "s1.example.com",

/LDAP_SERVER_([\d])/ => "l\\1.example.com" }
and those files will be copied, but modified so that in the destination
dir, all occurances of SERVER1 have been changed to s1.example.com and
the regexp substituted with the substitution string.

Is there any library for this? I've looked but not found. My current
approach is to create a small lib for this myself, using FileUtils, Find
and Tempfile. But it feels like this should be a common operation,
especially when doing installation scripts.

And before someone suggests it: no, I'm not at liberty to change the
tokens, so I can't embed ERb-tags in the source material.

--
Ola Bini (http://ola-bini.blogspot.com)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

"Yields falsehood when quined" yields falsehood when quined.
 
M

Matt Rose

I've done an even uglier hack for my makefiles at work.

I'd definitely be interested in it if you came up with something like
this.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top