0

I am rather new to Perl and would like to seek some advise on how to use Perl to detect if a files have populated a folder and then to move those files to a different location.

I have seen many codes that take about waiting for a specific file but my company uses a number randomizer for the files, so no two files have the same name.

Appreciate any help in this matter.

Thanks again.

Aaron

4

1 回答 1

1

更新:@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();
于 2012-08-15T05:10:36.600 回答