http://qs1969.pair.com?node_id=1061834

The_Dj has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks.

I need to watch for files appearing, dissapearing or changing.
My environment is Windows (several server versions) and Strawberryperl 5.18.
I also need to be as resource-light as possible as many target servers run at close to or over loaded.

Naturally Win32::FileSystem::Watcher seems to be the best solution since it does evrything I need

But I have a strange problem:
While the watcher is watching a directory any attempt to rename a file is met with a popup 'cannot rename <file> it is being used...'.
However I can create, modify or delete with no problems.

I'm testing with a very simple program:
use Win32::FileSystem::Watcher; my $watcher = Win32::FileSystem::Watcher->new("c:\\test"); $watcher->start(); while (1) { my @entries = $watcher->get_results(); foreach my $entry (@entries) { print $entry->action_name . " " . $entry->file_name . "\n"; } sleep 2; }
Any help?

Replies are listed 'Best First'.
Re: Watching for files to change
by kcott (Archbishop) on Nov 09, 2013 at 17:35 UTC

    G'day The_Dj,

    That's a known bug (#62454) that was raised over three years ago and is still flagged as "new".

    The bug report contains a potential solution that may be suitable for your needs.

    Another workaround might be to copy and delete instead of renaming.

    -- Ken

      Thanks, Ken

      That's brilliant! ☺
      The 'workaround' in the bug report looks to be better described as a 'fix'

      Any reason that can't be applied to the official CPAN module?

      Thanks again!
        "Any reason that can't be applied to the official CPAN module?"

        You'll need to contact the module author regarding that.

        -- Ken