Leser: 1
8 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/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 = <FILE>; close FILE; # Öffnet Template des einzufügenden Codes open (CODE, "N:/Scripts/etrackercode.txt"); local $/; $code = <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"; } }
1
2
3
4
5
6
7
8
9
10
11
etracker Code schon vorhanden: N:/Scripts/test/0198.htm
etracker Code schon vorhanden: N:/Scripts/test/0198.htm.bak
etracker Code schon vorhanden: N:/Scripts/test/0398.htm
etracker Code schon vorhanden: N:/Scripts/test/0498.htm
etracker Code schon vorhanden: N:/Scripts/test/test3/0198.htm
etracker Code schon vorhanden: N:/Scripts/test/test3/0198.htm.bak
etracker Code schon vorhanden: N:/Scripts/test/test3/0398.htm
etracker Code schon vorhanden: N:/Scripts/test/test3/04982.htm
etracker Code schon vorhanden: N:/Scripts/test/test3/test2/0198.htm
etracker Code schon vorhanden: N:/Scripts/test/test3/test2/0398.htm
etracker Code schon vorhanden: N:/Scripts/test/test3/test2/0498.htm
styx-cc+2008-01-24 10:43:54--Was haelst du von File::Find?
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl -w
use strict;
use File::Find;
use Cwd;
my $directory = "N:/Scripts/test";
find(\&insert_code, $directory);
sub insert_code {
if($File::Find::name =~ m/\.html$/i) {
print getcwd "-> $File::Find::name\n"; #ausgabe verzeichnis+dateiname
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use File::Find::Rule;
# find all the subdirectories of a given directory
my @subdirs = File::Find::Rule->directory->in( $directory );
# find all the .pm files in @INC
my @files = File::Find::Rule->file()
->name( '*.pm' )
->in( @INC );
# as above, but without method chaining
my $rule = File::Find::Rule->new;
$rule->file;
$rule->name( '*.pm' );
my @files = $rule->in( @INC );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $directory = "N:/Scripts/test";
find(\&insert_code, $directory);
sub insert_code {
if( -f $_ and /\.html$/i) {
print "$File::Find::dir -> $File::Find::name\n"; #ausgabe verzeichnis+dateiname
}
}
Strat+2008-01-24 13:33:13--oder kuerzer, ohne Cwd:
[...]
8 Einträge, 1 Seite |