H
Hike Mike
I am trying to list all files in a destination path that are newer than
the same file found in a source path (so I can quickly determine which
files have been modified in the destination since I obtained the
source). My strategy is to do a File::Find on the destination
top-level directory and, foreach file found, substitute the top-level
path of the absolute file path with the source path, store this in a
scalar and then compare the modification times of the two absolute
paths.
I think the problem is the s/// operator is not doing the substitution
because the strings used contain '/' string.
listNewerFiles.pl:
__BEGIN__
#!/usr/bin/perl
use strict;
use warnings;
use File::stat ":FIELDS";
use File::Spec::Functions 'catfile';
use File::Find;
die <<ERR unless @ARGV==2;
Supply a source path and destination path.
ERR
my $fromPath = $ARGV[0];
my $toPath = $ARGV[1];
opendir FROMDIR, $fromPath or die "ummmm: $fromPath: $!\n";
closedir FROMDIR or die "Cannot close $fromPath directory: $!";
opendir TODIR, $toPath or die "ummmm: $toPath: $!\n";
closedir TODIR or die "Cannot close $toPath directory: $!";
find (\&search, $fromPath);
sub search {
return unless grep { /\.java$/ } $_;
stat($_) or die "No $_: $!";
my $modFromTime = $st_mtime;
my $newPath = $File::Find::name;
print "fullpath: $newPath\n";
$newPath =~ s{$fromPath}{$toPath};
print "compare with: $newPath\n";
}
__END__
run on windows file system:
U:\perl>.\listNewerFiles.pl D:\projects\bullion-old
D:\projects\bullion-new
__OUTPUT__BEGIN__
fullpath:
D:\projects\bullion-old/appAuthen/src/com/myco/oesapp/authen/Auth
enPowers.java
compare with:
D:\projects\bullion-old/appClient/src/com/myco/appClient/Trad
er.java
__OUTPUT__END__
I was expecting:
compare with:
D:\projects\bullion-new/appClient/src/com/myco/appClient/Trader.java
the same file found in a source path (so I can quickly determine which
files have been modified in the destination since I obtained the
source). My strategy is to do a File::Find on the destination
top-level directory and, foreach file found, substitute the top-level
path of the absolute file path with the source path, store this in a
scalar and then compare the modification times of the two absolute
paths.
I think the problem is the s/// operator is not doing the substitution
because the strings used contain '/' string.
listNewerFiles.pl:
__BEGIN__
#!/usr/bin/perl
use strict;
use warnings;
use File::stat ":FIELDS";
use File::Spec::Functions 'catfile';
use File::Find;
die <<ERR unless @ARGV==2;
Supply a source path and destination path.
ERR
my $fromPath = $ARGV[0];
my $toPath = $ARGV[1];
opendir FROMDIR, $fromPath or die "ummmm: $fromPath: $!\n";
closedir FROMDIR or die "Cannot close $fromPath directory: $!";
opendir TODIR, $toPath or die "ummmm: $toPath: $!\n";
closedir TODIR or die "Cannot close $toPath directory: $!";
find (\&search, $fromPath);
sub search {
return unless grep { /\.java$/ } $_;
stat($_) or die "No $_: $!";
my $modFromTime = $st_mtime;
my $newPath = $File::Find::name;
print "fullpath: $newPath\n";
$newPath =~ s{$fromPath}{$toPath};
print "compare with: $newPath\n";
}
__END__
run on windows file system:
U:\perl>.\listNewerFiles.pl D:\projects\bullion-old
D:\projects\bullion-new
__OUTPUT__BEGIN__
fullpath:
D:\projects\bullion-old/appAuthen/src/com/myco/oesapp/authen/Auth
enPowers.java
compare with:
D:\projects\bullion-old/appClient/src/com/myco/appClient/Trad
er.java
__OUTPUT__END__
I was expecting:
compare with:
D:\projects\bullion-new/appClient/src/com/myco/appClient/Trader.java