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...

In reply to Interesting problem - AdvNotify by Foggy Bottoms

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.