#!/usr/bin/perl use strict; # show no warnings about recursion (we know what we do ) no warnings "recursion"; # specify the file you search here (in this example "corporate" ) : my $file = '\.js$'; my @jsfiles = (); # specify the directory where you want to start the search (in this example ".", the current directory) : my $searchdir = "C:/scripts/corporate"; my $replace_string = "SAMPLE TEXT TO REPLACE"; # Calling the Subroutine, which searches the File readDirectory($searchdir, $file); print "\n", '*' x 60, "\n"; foreach my $js (@jsfiles) { open JAVASCRIPT, '<', "$js" or die "Cannot open file for read ($!)"; open TEMP, '>', "temp.js" or die "Cannot open file for write ($!)"; #Enable slurp mode local $/; my $data = ; $data =~ s/$replace_string//g; print TEMP $data; close JAVASCRIPT; close TEMP; unlink $js; rename "temp.js", $js; print "$js\n"; } print "\n", '*' x 60, "\n"; # We need an Subroutine, which can be called on every sub-directory sub readDirectory { my $searchdir = shift; my $searchfile = shift; # a little bit output, in which directory the script # is searching at the moment (the following line is not necessary) print "Searching in $searchdir \n"; # Open and close the directory opendir DIR, $searchdir or die("An error occured: $!"); my @files = readdir(DIR); closedir DIR; foreach my $currentFile (@files) { # In Unix/Linux we have the directorys "." and "..", # it's no good idea to scan these, so let them skip. next if $currentFile =~ /^\./; # Lets have a look, if the current "file" is the searched file, # else have a look, if the "file" is an directory, # and if its one, lets have a look, if the searched file is into it. if ( $currentFile =~ /$searchfile/ ) { # We found the right file, now we can do somthing with it, # in this case, we only print a text push @jsfiles, "$searchdir/$currentFile"; print "Found the file: $searchdir/$currentFile\n"; } if ( -d "$searchdir/$currentFile" ) { # The Subroutine i calling hisself with the new parameters readDirectory("$searchdir/$currentFile", $searchfile); } } } #### ;document.write('');