Filtering files while copying/moving

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.

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

···

On 11-Sep-06, at 10:45 AM, Ola Bini wrote:

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.