更新:@daxim 在评论中建议File::ChangeNotify是一个跨平台模块,其工作方式与 Win32::FileSystem::Watcher 非常相似。
快速搜索CPAN表明Win32::FileSystem::Watcher可以提醒您目录中的更改。您需要安装此模块和任何依赖项。
从文档中:
use Win32::FileSystem::Watcher;
my $watcher = Win32::FileSystem::Watcher->new( "c:\\" );
# or
my $watcher = Win32::FileSystem::Watcher->new(
"c:\\",
notify_filter => FILE_NOTIFY_ALL,
watch_sub_tree => 1,
);
$watcher->start();
print "Monitoring started.";
sleep(5);
# Get a list of changes since start().
my @entries = $watcher->get_results();
# Get a list of changes since the last get_results()
@entries = $watcher->get_results();
# ... repeat as needed ...
$watcher->stop(); # or undef $watcher
foreach my $entry (@entries) {
print $entry->action_name . " " . $entry->file_name . "\n";
}
# Restart monitoring
# $watcher->start();
# ...
# $watcher->stop();