[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Filtering files while copying/moving.

Ola Bini

9/11/2006 2:46:00 PM

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.bl...)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http:/...)
OLogix Consulting (http://www....)

"Yields falsehood when quined" yields falsehood when quined.


1 Answer

Matt Rose

9/13/2006 12:47:00 AM

0

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.bl...)
> JvYAML, RbYAML, JRuby and Jatha contributor
> System Developer, Karolinska Institutet (http:/...)
> OLogix Consulting (http://www....)
>
> "Yields falsehood when quined" yields falsehood when quined.
>