views:

368

answers:

3

Conditions:

  • Windows 98 SE
  • WMI not available

I have code that looks like this, written using my steroidal wrapping of VBScript using MSScript.

do
 a = files.collectfiles( "c:\userver", "" )
 for i = 0 to ubound( a )
  f = a(i)
  if strings.endswith( f, ".usv" ) then
   d = files.readfilee( f )
   on error resume next
   executeglobal d
   nErr = err.number
   sErr = err.description
   on error goto 0
   if nErr <> 0 then
    trace "*** Error " & nErr & ", " & sErr
   end if
   files.deletefile f
  end if
 next
 system.sleep 10
 system.cooperate
loop

There's a lot of disk activity with that call to files.collectfiles. Is there some way of detecting a change in the contents of a folder without actually scanning the folder for files?

+1  A: 

Define "change in the contents of a folder".

If it means that a file was added, deleted, or renamed, then the modified timestamp of the folder is updated whenever such an event occurs.

If you're instead wanting to know when files are modified, then you'll need to read them.

That said, looking at what you're trying to do (scan a folder for new .usv files, and process them and delete them), then just keeping track of the timestamp on the folder and updating it right before you call collectfiles is best (note that the correct time to log is just BEFORE calling collectfiles, otherwise you run the risk of not waking up if a file gets added during the collectfiles call or immediately afterward).

Yuliy
Links are always helpful, but this kind of good advice is marvellous. Thanks very much for your input.
boost
A: 

You specifically asked for something in VB and running on win98 and I have no answer for this, but MS has a c/win32 example on how to achieve this on Windows2000+ with FindFirstChangeNotification. Another thing is that apparently "FileSystemWatcher" in .NET is not working/supported on Win98. What is my point? There maybe is no easy solution for this and you have to come up with something on your own.

merkuro
+1  A: 

There is a sample which claims to work on all versions from Win95 up to at leas WinXP. Developed under Win98 with VB5. Using the (then? provided links to the docu below) undocumented SHChangeNotify* Functions.

SHChangeNotifyRegister: Receive Shell Change Notifications

SHChangeNotifyRegister Function SHChangeNotifyDeregister Function

There is another solution using ReadDirectoryChangesW here:

VB6 WinAPI ReadDirectoryChangesW (check the 5th post from Yang Kok Wah)

jitter