Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Find all files created after a certain date
nipper
I was requested to get a list of all files created after a certain date.
1st plan was:
foreach $file
$date = `iwattrib $file crdate`;
However that date returns the date the version was created, not when the object was created.
Only option I can think of (which will be painfully slow)
foreach $file
get crdate
get previous_version
while (crdate > DATE && previous_version_exists)
get previous_version
get crdate
if (! previous version and crdate > DATE) {FOUND ONE}
end while
Any better approaches ?
Am I missing something ?
Tips/Pointers/RTFMs appreciated
Andy
Find more posts tagged with
Comments
Adam Stoller
Hmm - interesting ... okay - I just threw this together and did some very brief testing of it - but I believe it will do what you want. I'm not sure if there's any more efficient way of doing this, but ...
use Getopt:
td;
use Date::Manip;
use TeamSite::Config;
use strict;
my $iwhome = TeamSite::Config::iwgethome();
my $iwmnt = TeamSite::Config::iwgetmount();
my %opts = ( p => "",
d => "",
);
sub usage{
my $msg = shift;
die("\n*** $msg\n\nUsage: $0 -p path -d date\n\n" .
"path\t-the path to start looking from\n" .
"date\t-files must be created after specified date.\n\n");
}
usage("Unrecognized option") if (!getopts("p:d:", \%opts));
usage("Missing path information") if ($opts{p} eq "");
usage("Bad path [$opts{p}]") if ($opts{p} ne "" && ! -d $opts{p} && ! -d "$iwmnt$opts{p}");
usage("Missing date") if ($opts{d} eq "");
my $startdir = $opts{p};
$startdir =~ s/^/$iwmnt/ if ($startdir !~ /^$iwmnt/);
my %FILES = ();
process_dir($startdir, \%FILES, $opts{d});
print "[$FILES{$_}]: $_\n" foreach(sort(keys(%FILES)));
sub process_dir{
my($dir, $flist, $date) =
@_
;
my
@subdirs
;
return if (! -d $dir);
if (!opendir(DIR, $dir)){
warn("[opendir] '$dir' ($!)");
return;
}
my
@entries
= readdir(DIR);
closedir(DIR);
foreach(
@entries){
next if /^\.+$/;
next if /^(EDITION|WORKAREA)$/;
push(
@subdirs
, "$dir/$_") if (-d "$dir/$_");
process_file("$dir/$_", $flist, $date) if (-f "$dir/$_");
}
process_dir($_, $flist, $date) foreach(
@subdirs)
;
}
sub process_file{
my($file, $flist, $date) =
@_
;
$file =~ s|^$iwmnt||;
my $cmd = "$iwhome/bin/iwrlog -m $file";
my
@rlog
= `$cmd`;
my
@v1
= split(/\t/, pop(
@rlog))
;
my $err;
my $delta = &DateCalc("$v1[2]", "$date", \$err);
$flist->{$file} = $v1[2] if ($delta =~ /^-/);
}
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Migrateduser
You sure are generous, Adam.
Raise your hand if you would custom write an application for someone who posts a question on DevNet. Hmmm... Not seeing too many hands raise.
Thanks for all your help, Adam... YOU ROCK!
- Jason
Adam Stoller
It was an interesting problem, and I don't have to comment or document the code - so it's a bit easier to toss it off. The main part of it was the use of iwrlog rather than iwattrib - because I believe that iwrlog provides what you want more effectively.
Unfortunately, you still have to end up invoking the CLT for each and every file you find along the way - and that's kind of expensive.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
nipper
You know fish, you could have just said, use iwrlog.
Anyway thanks, that was very nice. I already have a (slow) on that uses iwattrib
to traverse through old versions. I will replace that coe with this (but having both will
help be verify accuracy)
If we ever end up at a users group meeting together I will buy some sushi. Smitty & I can split
the beer.
Andy
nipper
>It was an interesting problem, and I don't have to comment or document the code - so it's a bit easier to toss it off. The main part of it was the use of >iwrlog rather than iwattrib - because I believe that iwrlog provides what you want more effectively.
>Unfortunately, you still have to end up invoking the CLT for each and every file you find along the way - and that's kind of expensive.
Well I am glad I could challenge you.
This will still be much faster than my approach, which took at least 1 iwattrib (crdate), and possibily more for previous versions and
crdates for those.
Never ran accross iwrlog before, lot of parsing but still much better that CLTs.
Andy
Migrateduser
Hey here's one I just whipped up:
print "Hello World!\n";
Whew...I think I'll take the rest of the day off. Does that mean you have to buy all the beers since I also helped?
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com