Find & Replace within the files of a folder tree recursively
[email protected] (Detlef Lindenthal) Fri, 25 Mar 2005 11:45:04 +0100
| Newsgroups | perl.macperl |
|---|---|
| Message-ID | <[email protected]> |
--------------050807000400040602010402
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Does someone have a tool to replace one string by some other string
within all files of a folder tree recursively?
(I once wrote a perl script for this, but it only functioned if I copied
each file to some other destination.)
Now I just RTFM and found these beautiful scripts in the Perl Cookbook,
p. 323:
##################################################
##
## Type alle the names and paths of the files within a folder tree:
##
##################################################
use File::Find;
@ARGV = qw(.) unless @ARGV;
find sub { print $File::Find::name, -d && '/', "\n" }, @ARGV;
#################### E N D ########################
and
##################################################
##
## Find the biggest file within a folder tree:
##
##################################################
use File::Find;
@ARGV = qw(.) unless @ARGV;
my ($saved_size, $saved_name) = (-1, '');
sub biggest {
return unless -f && -s _ > $saved_size;
$saved_size = -s _;
$saved_name = $File::Find::name;
}
find (\&biggest, @ARGV);
print "Biggest file $saved_name in @ARGV has $saved_size bytes length.\n";
#################### E N D ########################
Now again my question:
Can someone add some lines, so I can do search-and-replace within each file?
TIA,
Detlef Lindenthal
--------------050807000400040602010402--