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; }
In reply to Reset the time after a readdir by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |