Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting when a file appears

Status
Not open for further replies.

jpasquini

Programmer
Apr 20, 2006
44
US
Has anyone out there seen an example of having a block of code execute when a file is deleted or renamed?

Basically I need to do this:

if ( -f "file_complete" )
{ print "The process is done! Press B to
continue\n" }

The problem is the way TK works, you have this "MainLoop" line and there it sits while the program runs, never checking this line.
I believe it has to be some kind of 'bind event' but can't find anything further on it in any of the books...................




 
use an absolute path '/usr/bin/file_complete' or whatever the path to the file is ..

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
The problem is that the IF code never gets checked. Perl TK hangs on the line MainLoop; and waits for you to click a button or object.

If you put the IF code in the program, it will only check one time through, then go to MainLoop and wait for you to type or click something before budging.



 
Can we see a cut down version of the code? Talking about what's not tangible, is merely politics ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
You don't *need* the MainLoop. You can use your own loop. ;)

Replace MainLoop with this:
Code:
while (1) {
   # sleep a millisecond
   select (undef,undef,undef,0.01);

   # update windows
   $mw->update;

   # check other conditions or something?
   if (-f ...) {
      ...
   }
}
 
************************
* EXCELLENT *
************************

$mw-> update; in the loop
That did the trick!
It checks the IF line.

As on Who Wants to be a Millionaire, "It's always easy if you know the answers".

kudos all around.

 
##############################################
## This subroutine creates a scrolled window
## which displays the contents of a log file
## as it is being written
##---------------------------------------------

open (LOG, "tail -f -n 25 ${batch_script_directory}LOG_$_[0]|") or die "Tail file error: $OS_ERROR:\n\n${batch_script_directory}LOG_$_[0]";

my $status_text = $mw->Text(-width => 80, -height => 25, -wrap => 'none');
$status_text->pack(-expand => 1);
$mw->fileevent(LOG, 'readable', [\&fill_text_widget, $status_text]);


sub fill_text_widget
{
my($widget) = @_;
$_ = <LOG>;
$widget->insert('end', $_);
$widget->yview('end');
} # end fill_text_widget


$batch_run_file = $_[0];


........later that program...........

while ( ! -f "${batch_script_directory}${batch_run_file}_complete" )
{
$mw->update;
### wait here.......
}
 
Sorry...there is a batch program that is system called that writes to the logfile while it is running, and when it is finished it renames the log by adding "_complete" to the end.

The program scrolls the logfile on the screen as the batch prog is running, then when it finds the file ending in "_complete" in the working directory, it knows it is done.

Good enough.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top