Check file date before getting folder path

Hi - I just asked the below question in another ticket, but i want some extension to it.

I have a requirement where I want to find whether any files are in the given folder.
So I listed all the folder paths in a text file and want to send that file as input to perl script
now perl script reads each line and gets each folder path and should check whether it contains any files
if it contains any files then it should print that folder path into the output file.
that's my original question but now I want to print the output file only if the file contained in the folder is one day old.

Example:
Inputfile.txt is as below
C:\temp\f1
C:\temp\f2


f1 has one file that has modified date from 3 days go, but f2 has file that is created like an hour back.
so when I run the perl script I should only get
C:\temp\f1

use strict;
use warnings;
use Pod::Usage;
use Getopt::Long;
use Time::Piece;

my $helpme = 0;
my $man = 0;

my $inputFileName = 'C:\\temp\\input.txt';
my $outputFileName = 'C:\\temp\\output.txt';
my $fileModifiedDate = '';
my $errorcode = 0;
my $DEBUG=0;

if(exists $ENV{DEBUG}) {
	$DEBUG = ($ENV{DEBUG} eq "") ? 0 : $ENV{DEBUG};
}

GetOptions('help' => \$helpme, 'man' => \$man, 'infile=s' => \$inputFileName, 'outfile=s' => \$outputFileName) or pod2usage(2);

pod2usage(1) if $helpme;
pod2usage(-verbose => 2) if $man;

die 'No input file name specified!' unless $inputFileName;
die 'No output file name specified!' unless $outputFileName;

open(INFILE, '<', $inputFileName) or die "Could not open input file: $!";
open(OUTFILE, '>', $outputFileName) or die "Could not open/create output file: $!";

while( my $dir = <INFILE>) {
	chomp $dir;
	opendir DIR, $dir or die "could not open dir $dir: $!";
	if (grep { $_ ne '.' and $_ ne '..' } readdir DIR) {
					print OUTFILE $dir, "\n";
	}
        closedir DIR;
}

close INFILE;
close OUTFILE;

exit $errorcode;
                                          

Open in new window


so now I would like to add condition something like below
$fileModifiedDate = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime(( stat filename )[9]));
            if($fileModifiedDate < currentDate -1)
            {
                              print OUTFILE $dir, "\n";
            }

can you guys please help me with the missing piece.

Thanks,
shragiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
if (grep { $_ ne '.' and $_ ne '..' and  -M "$dir/$_" > 1 } readdir DIR) {
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.