nfaber has asked for the wisdom of the Perl Monks concerning the following question:
#!D\perl\bin\perl.exe -w use strict; my (%dirlist, %loglist, @difference, $dir); unless ($dir = $ARGV[0]) { die "Needs a directory.";} $dir =~ s(\\+)(/)g; unless (-d $dir) {die "This is not a valid directory. $!";} my $logfile = "${dir}/mydirlog.txt"; opendir DIR, "$dir"; while ($_ = readdir(DIR)) {$dirlist{$_}++;} closedir DIR; if (-e $logfile) { open (OLDLOG, $logfile) or die "Cannot open existing log file.\n$! +"; while (<OLDLOG>) {chomp; $loglist{$_}++;} close OLDLOG; foreach my $dirName (keys %dirlist) { unless (defined $loglist{$dirName}) { push @difference, "$dirN +ame";} } foreach my $logName (keys %loglist) { unless (defined $dirlist{$logName}) { push @difference, "$logN +ame";} } } open LOG, "> $logfile"; foreach (keys %dirlist) { print LOG "$_\n"; } close LOG; print "@difference";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check for a new file in a directory
by insensate (Hermit) on Apr 21, 2004 at 15:52 UTC | |
by nfaber (Initiate) on Apr 21, 2004 at 16:33 UTC | |
|
Re: Check for a new file in a directory
by AcidHawk (Vicar) on Apr 22, 2004 at 07:40 UTC |