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
use strict;
use File::Copy;
use File::Basename;
# Input Data A
my $FROM='D:\projects\A';
# Input Data B
my $TO='D:\projects\B';
my @IU = glob($FROM."\\*");
my $IU=@IU;
for (my $i=0;$IU[$i];$i++)
{
$IU[$i] = basename($IU[$i]);
}
for (my $i=0;$IU[$i];$i++)
{
my @Suffix = split /\./, $filename;
my $ISO3 = $Suffix[0];
my @StatFROM = stat($FROM\\$IU[$i]);
my @StatTO = stat($TO."\\".$ISO3."\\".$IU[$i]);
}
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
#! perl use strict; use warnings; use 5.010; use Data::Dumper; # brings Dumper for Checking # find_files( "/dirA" => "extA", "/dirB" => "extB" ); # extensions without dot sub find_newer_files { my ( $dirA, $extA, $dirB, $extB ) = @_; # read files and their mtime from dirA into a hash (fname => mtime) chdir $dirA or die "chdir($dirA) failed: $!"; my %files_in_A = map { $_ => (stat $_)[9] } glob("*.$extA"); # read files and their mtime from dirB into a hash (fname => mtime) chdir $dirB or die "chdir($dirB) failed: $!"; my %files_in_B = map { $_ => (stat $_)[9] } glob("*.$extB"); # for each found file in dirA for my $fileA ( keys %files_in_A ) { # replace extension for wanted file in dirB ( my $fileB = $fileA ) =~ s{\.\Q$extA\E$}{.$extB}; warn "$fileA -> $fileB\n" if $ENV{DEBUG}; # if we found a fileB in dirB if ( exists $files_in_B{$fileB} ) { # compare the timestamp; tell us when fileB is older than fileA if ( $files_in_A{$fileA} > $files_in_B{$fileB} ) { say "$fileB is older than $fileA"; } } } warn Data::Dumper->new( [ \%files_in_A, \%files_in_B ], [ '*files_in_A', '*files_in_B' ] )->Dump() if $ENV{DEBUG}; } find_newer_files( "/tmp/A" => "adl", # directory_A => extension_A "/tmp/B" => "adlt", );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
find_newer_files(
$dirA => "adl", # directory_A => extension_A
$dirB => "ADLT", # directory B
);
find_newer_files(
$dirA => "lin", # directory_A => extension_A
$dirB => "LINT", # directory B
);
find_newer_files(
$dirA => "red", # directory_A => extension_A
$dirB => "REDT", # directory B
);
find_newer_files(
$dirA => "reg", # directory_A => extension_A
$dirB => "REGT", # directory B
);
find_newer_files(
$dirA => "red", # directory_A => extension_A
$dirB => "REDT", # directory B
);
1
2
3
4
find_newer_files(
$dirA => ["adl","red"], # directory_A => extension_A
$dirB => ["ADLT","REDT"], # directory B
);
guest moist halt keine Fehlerbeschreibung, mit der man was anfangen kann. Also gibt es kein Problem. Sorry.noch funktioniert es nicht richtig...
1 2 3 4 5 6 7 8 9 10
print Dumper hstat($0); # Namen statt Index sub hstat{ my $file = shift; my @names = qw(dev ino mode nlink uid gid redv size atime mtime ctime blksize blocks); my %h = (); @h{@names} = stat $file; return \%h; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$VAR1 = {
'atime' => 1493309871,
'blksize' => '',
'blocks' => '',
'ctime' => 1367948039,
'dev' => 2,
'gid' => 0,
'ino' => 0,
'mode' => 33206,
'mtime' => 1493309871,
'nlink' => 1,
'redv' => 2,
'size' => '3141',
'uid' => 0
};
1 2 3 4 5 6
my $mtime = hstat($file)->{mtime}; my $atime = hstat($file)->{atime}; if( hstat( $file_1 )->{ctime} == hstat( $file_2 )->{ctime} ) { print "Die Dateien wurden zu selben Zeit erstellt"; }
perl -wE'say "Datei 1 ist " . (-M $ARGV[0] > -M $ARGV[1] ? "" : "nicht "). "älter als Datei 2"' <file1> <file2>