The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

File::Hotfolder - recursive watch directory for new or modified files

SYNOPSIS

    use File::Hotfolder;

    # object interface
    File::Hotfolder->new(
        watch    => '/some/directory',
        callback => sub { 
            my $path = shift;
            ...
        },
    )->loop;

    # function interface
    watch( '/some/directory', callback => sub { say shift } )->loop;

    # watch a given directory and delete all new or modified files
    watch( $ARGV[0] // '.', delete  => 1, print => DELETE_FILE )->loop;

DESCRIPTION

This module uses Linux::Inotify2 to recursively watch a directory for new or modified files. A callback is called on each file with its absolute path.

Deletions and new subdirectories are not reported but new subdirectories will be watched as well.

CONFIGURATION

watch

Base directory to watch

callback

Callback for each new or modified file. The callback is not called during a write but after a file has been closed.

delete

Delete the modified file if a callback returned a true value (disabled by default).

fullname

Return absolute path names (disabled by default).

filter

Filter filenames with regular expression before passing to callback.

print

Print to STDOUT each new directory (print & WATCH_DIR), each file path before callback execution (print & FOUND_FILE), and/or each deletion (print & DELETE_FILE).

scan

First call the callback for all existing files. This does not guarantee that found files have been closed.

METHODS

loop

Watch with a manual event loop. This method never returns.

anyevent

Watch with AnyEvent. Returns a new AnyEvent watch.

inotify

Returns the internal Linux::Inotify2 object.

SEE ALSO

File::ChangeNotify, Filesys::Notify::Simple, AnyEvent::Inotify::Simple

AnyEvent

rrr-server from File::Rsync::Mirror::Recent

COPYRIGHT AND LICENSE

Copyright Jakob Voss, 2015-

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.