Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: how to permanently monitor a directory

by erasei (Pilgrim)
on Aug 14, 2003 at 13:15 UTC ( #283857=note: print w/replies, xml ) Need Help??


in reply to how to permanently monitor a directory

Well, like all things Perl, TISMTOWTDI.

If you know what the files will be (example, they are uploaded by a script so the filename will always be the same) you could do something like:

while (1) { if (-e "/my/dir/filename.dat") { do_something_now(); } }
If not, you could use your own code. I'm not sure I'd have it 'sleep' though. Run it from cron every so often would make more sense to me. Also, you can drop a couple of lines by changing
my $items_in_dir = @Dircontent; if ($items_in_dir > 2) ..
to
if (scalar(@Dircontent) > 2) ..

Replies are listed 'Best First'.
Re: Re: how to permanently monitor a directory
by LanceDeeply (Chaplain) on Aug 14, 2003 at 13:50 UTC
    This:
    my $items_in_dir = @Dircontent; if ($items_in_dir > 2) ..
    won't work if some smart alec decides to create a subdir in your drop area. try using -f

    TISMTOWTDI:

    use strict; use warnings; sub scandir { my $dir = shift; my $fileProcessor = shift; opendir (DIR, $dir) or die "Cannot open $dir: $!\n"; for (readdir DIR) { if ( -f ) { &$fileProcessor($_); } } close DIR; } sub do_something { my $filename = shift; print "got file: $filename\n"; } sub do_something_else { my $filename = shift; print "got another file: $filename\n"; } scandir('.',\&do_something); scandir('.',\&do_something_else);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://283857]
help
Chatterbox?
[Discipulus]: if is the author of a patch, is more like a 'request to push' into rather than a pull request..
[choroba]: as it's considered unpolite to push to someone else's repo
[choroba]: and in fact, you don't push into the target repo, you push into your branch of your fork
[choroba]: the maintainer of the upstream repo than "merges" the pull request, i.e. they pull from your fork into the upstream
[Discipulus]: ' i.e. you asked them to pull from your repo' =~ I (subj) want to push
[Discipulus]: chorobayour words are reasonable
[choroba]: I'm just repeating some else's words as I remembered them after having asked the same question
[choroba]: s/some/someone/
Discipulus what a pity all people do not speak only in eatalian..
[choroba]: we'd need video calls more often :)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-05-27 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?