#!/usr/bin/perl -s use Cwd; # module for finding the current working directory &ScanDirectory("N:/Scripts/test"); # This subroutine takes the name of a directory and recursively scans # down the filesystem from that point looking for HTML files sub ScanDirectory{ my ($workdir) = shift; my ($startdir) = $workdir; # keep track of where we began chdir($workdir) or die "Unable to enter dir $workdir:$!\n"; opendir(DIR, ".") or die "Unable to open $workdir:$!\n"; my @files = readdir(DIR) or die "Unable to read $workdir:$!\n"; closedir(DIR); foreach my $file (@files){ if ((-d $file) and ($file ne ".") and ($file ne "..")) { # is this a directory? &ScanDirectory(Cwd::realpath('.') . "/" . $file); next; } if (($file =~ m/\.htm/) || ($file =~ m/\.php/)) { $file2 = $file; open (FILE, $file2); local $/; $content = ; close FILE; # Öffnet Template des einzufügenden Codes open (CODE, "N:/Scripts/etrackercode.txt"); local $/; $code = ; close CODE; @name = split(/\./, $file); # Verzeichnisname @path = split(/\//, Cwd::realpath('.')); $code .= "blablabla"; # Fügt variable Informationen ein # Prüft, ob Code bereits in der Datei vorhanden ist if ($content =~ m/etracker PARAMETER 2.4/) { print "etracker Code schon vorhanden: ".Cwd::realpath('.')."\/$file2\n"; } # Sonst: Füge Code in HTML ein und speichere neues HTML else { $content =~ s/\<\/body\>/$code\<\/body\>/g; open (TEST, ">$file2"); print TEST $content; close TEST; } } # End IF chdir($startdir) or die "Unable to change to dir $startdir:$!\n"; } }