C:\WINNT\Profiles\702031609\Personal>mkdir toto
C:\WINNT\Profiles\702031609\Personal>rmdir toto
C:\WINNT\Profiles\702031609\Personal>mkdir toto
####
c:\WINNT\Profiles\702031609\Personal (c:\WINNT\Profiles\702031609\Personal)
key : filename -> content : c:\WINNT\Profiles\702031609\Personal
key : action -> content : FILE_ACTION_MODIFIED
---while---
####
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 object");# create watch object
# scan main drive (c:\) for any possible change.
(my $thread=$obj->StartThread(Directory=>$folder,Filter=>All,WatchSubtree=>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 as 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;
}
####
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";
}