Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Interesting problem - AdvNotify

by Foggy Bottoms (Monk)
on Aug 20, 2003 at 11:18 UTC ( [id://285211]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Foggy Bottoms has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I posted a little earlier a question regarding regexes and a ban/force folder search...

The main aim of my code is to detect changes in files/folders but since a hard drive can get pretty big, the idea was to have a force/ban folder. The default is to scan everything, but then if you don't want to scan c:\winnt then you can ban that folder and its subfolders. And in the case you'd want to scan one of its subfolders then you can add it to the force list...

I've now completed my code and it seemed to be working fine until I ran a little very simple test :
Test : while my code is running I start up a new DOS prompt (I'm using WinNT 4.0) and do the following :
C:\WINNT\Profiles\702031609\Personal>mkdir toto C:\WINNT\Profiles\702031609\Personal>rmdir toto C:\WINNT\Profiles\702031609\Personal>mkdir toto

The winnt folder is banned but the personal one isn't so the scan is activated... When I do the first mkdir I get in the other window (the perl one) the following :
Output :
c:\WINNT\Profiles\702031609\Personal (c:\WINNT\Profiles\702031609\Pers +onal) key : filename -> content : c:\WINNT\Profiles\702031609\Personal key : action -> content : FILE_ACTION_MODIFIED ---while---
But when I run the rmdir and the last mkdir, it fails... (it doesn't return anything but the while print...).

Here's my bit of code :
sub startScan { # read parameters my @wantedF = @{+shift}; my @bannedF = @{+shift}; my $scanType= shift; my $folder = "c:\\"; my $obj = new Win32::AdvNotify() or die ("Can't create AdvNotify ob +ject");# create watch object # scan main drive (c:\) for any possible change. (my $thread=$obj->StartThread(Directory=>$folder,Filter=>All,WatchS +ubtree=>Yes)) or die ("Can't start thread."); $thread->EnableWatch() or die "Problem starting EnableWatch()\n"; $obj->Wait(Win32::AdvNotify::INFINITE); # block code here as long a +s no change comes up. # store data of file/folder changed my @data; my $ret = $obj->Read(\@data); my %changes; for (0..@data-1) # for each change detected { my $filename = @data[$_]->{'Directory'}.@data[$_]->{'FileName'}; my $path=$filename; if (not isFolder($filename)) { $filename =~ /^(.*)\\/; # returns path part of the filename $path = $1; } if (compareFolder($path,$scanType,\@wantedF,\@bannedF)==ACCEPTED +) { # print "@data[$_]->{'FileName'} : ACCEPTED\n"; # print "Action :".$ActionName{@data[$_]->{'Action'}}."\n" +; # debug purposes # print "---------------------------\n"; if ( isFolder($filename) or $filename =~ /\.doc|\.ppt|\.xls|\ +.pdf$/ ) { print "$filename ($path)\n"; $changes{filename} = $filename; $changes{action} = $ActionName{@data[$_]->{'Action'}}; } } } return %changes; }
and the call to the function :
my @wantedF; # folders to be scanned my @bannedF; # banned folders not to be scanned @wantedF = ('C:/My Documents', 'C:/WINNT/Profiles/702031609/Personal', 'd:/', 'D:/brossad/photos'); @bannedF = ('c:/win32app', 'C:/TEMP', 'c:/recycler', 'c:/winnt', 'd:/perl', 'd:/brossad'); while (1) { my %changes = startScan(\@wantedF,\@bannedF,INC_SUBDIRS); foreach my $k (keys %changes) { print "key : $k -> content : $changes{$k}\n"; } print "---while---\n"; }
I've a feeling there's a memory problem with AdvNotify : perhaps I should clean up after its use like shutting it down or deleting change detections after I dealt with them (or is there no need ?).
Thanks for your help...

Replies are listed 'Best First'.
Cleaning up with Free...
by Foggy Bottoms (Monk) on Aug 20, 2003 at 11:28 UTC
    I had a look at the AdvNotify.pm file and tried using the $obj->Free() method but when I ran my code, it returned
    Runtime error 216 at 0000ED62 Press any key to continue . . .

    What does that mean - apart from the fact that I'm not doing it right ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://285211]
Approved by RMGir
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.