Hi there,
I'm writing some Perl which takes TV shows recorded on Windows Media Center and moves/renames/deletes them depending on certain criteria.
Since the Perl runs fairly frequently, I'd like to cleanly determine whether or not the file is in use (in other words, the show is in the process of being recorded) so I can avoid doing anything with it.
My current method looks at the status of a file (using "stat") and compares it again after 5 seconds, like so:
sub file_in_use
{
my $file = shift;
my @before = stat($file);
sleep 5;
my @after = stat($file);
return 0 if ($before ~~ $after);
return 1;
}
It seems to work, but I'm concious that there is probably a better and cleaner way to do this.
Can you please advise?