Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am reading a directory for files and if the files are newer than say X then I would like to copy them. The issue I am having is that I cannot reset the time when the while loop reads the directory again. So if the file is newer than X the next time through the loop it reads the same time so that action is constantly repeated. I am hoping on each loop through that the time of how old the files will be updated by the value of X. So if my if statement becomes untrue the action will stop
Here is my code##! /usr/local/bin/perl use strict; use warnings; use File::Copy; my $sleep = 10; my $dirname = "Directory A"; my $dirname2 = "Directory B"; my $filterstring = "\\.jpg\$"; while (1) { opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n"; foreach my $file (readdir (DIR)) { next if not $file =~ m/$filterstring/; $file = $dirname.'/'.$file; print "found $file, mtime: ".(-M $file)."\n"; if (-f $file && (0.0005 > -M $file)){ my $capture = $dirname . $file; my $qc = $dirname2; print "Copying $file to $qc\n"; copy($file, $qc); reset; } } reset ; closedir (DIR); sleep $sleep; 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reset the time after a readdir
by Anonymous Monk on Oct 21, 2014 at 23:28 UTC | |
by Anonymous Monk on Oct 21, 2014 at 23:44 UTC | |
|
Re: Reset the time after a readdir
by Laurent_R (Canon) on Oct 22, 2014 at 07:03 UTC | |
|
Re: Reset the time after a readdir
by soonix (Chancellor) on Oct 23, 2014 at 07:48 UTC |