Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

smart way of scanning hard drive for file & folder changes

by Foggy Bottoms (Monk)
on Jul 31, 2003 at 09:59 UTC ( [id://279523]=perlquestion: print w/replies, xml ) Need Help??

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

Monks of Nepal and abroad, good morning, I've been wanting to scan my hard drive to find files & folders that'd changed (ie created/modified/deleted). There's a simple of scanning the entire drive and checking to see whether last modified dates have been changed - but it's very time consuming.
Hence, I thought of another way : firstly there's no need to scan if no changes have been made. So a disk scan should only be triggered when a change is detected - that bit was easily solved with  Win32::ChangeNotify->new("c:\\",1,"LAST_WRITE");. However this bit doesn't tell me what's changed or where.
Therefore I thought of using a folder's last accessed property, but it so happens that this property doesn't give a complete timestamp - hence it's not precise enough. As for the modified property of a folder, it is not reflected up in a folder tree : if a change occurs 3 folders down in depth then only the directly parent folder is affected.
I'm basically stalling at this point - on one hand I've got this great tool but it returns a "crappy" timestamp and on the other hand I have this really complete timestamp but unfortunately, it's not being reflected on parent folders.
There is some hope however with
FindFirstChangeNotification 
, a C++ method...
Has anyone ever wanted to look up modified files in an efficient way ? Has anyone advice I could use, tips, or help ?

Thanks so much guys...

Replies are listed 'Best First'.
Re: smart way of scanning hard drive for file & folder changes
by Cine (Friar) on Jul 31, 2003 at 13:03 UTC
    Yes, many people. But most uses are seen for individual files or directories, not complete drives.
    So the work-around would be to simple add a notification for every subdir on your drive.
    Secondly, even on windows atime can be turned of ("a folder's last accessed property"), so you can't rely on that.

    T I M T O W T D I
      Yes I did notice that you could turn the atime off so it's reliable.
      Luckily enough I managed to get my hands on the long lost Win32::AdvNotify package which you can find at http://idnopheq.perlmonk.org/perl/packages.

      I then wrote up a little script (see below) that tells you when a change occurs, what type of change it is and what file/folder was affected - it's simply grand !!!
      Thanks for your input and here's my code :
      NB: you need Win32::API and Data::Dumper as well as the Win32::AdvNotify packages.
      use strict; use Data::Dumper; use Win32::AdvNotify qw (Yes No All); my $obj = new Win32::AdvNotify() or die ("Can't create AdvNotify object"); (my $thread=$obj->StartThread(Directory=>"d:\\brossad",Filter=>All, WatchSubtree=>Yes)) or die ("Can't start thread."); $thread->EnableWatch() || die "Problem starting EnableWatch()\n"; while (!$obj->Wait(200)) # time in milliseconds { print ".";#wait and see } my @data; my $ret = $obj->Read(\@data); print Dumper(@data); # very important line - don't forget it $thread->Terminate(); $obj->Free;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://279523]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found