shragi
asked on
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
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,
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;
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,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.