Get notification from system on directory contents change

PaulSchrum

Registered User.
Local time
Today, 10:47
Joined
Jul 30, 2011
Messages
20
Hi All,

I am using the Dir statement to get info on directory contents. (Thanks to Allen Browne's free information for how to do that.)

I realized that when the directory contents change while I have it open via Windows Explorer (say someone else adds a file), Windows Explorer receives notification of that somehow and repaints itself to show the updated values.

Is it possible (and then how) to get notified by the system that the directory has changed so I can requery it? Or how is Windows Explorer doing this in a way that I can emulate it?

TIA for any and all help.

- Paul
 
ummmm...

how long does the procedure run? What you're asking is pointless, almost. If the routine is more than 5 seconds long, that's a feat in itself, and what are the odds that someone adds a file to the dir you're checking in that 5 seconds?
 
ummmm...

how long does the procedure run? What you're asking is pointless, almost. If the routine is more than 5 seconds long, that's a feat in itself, and what are the odds that someone adds a file to the dir you're checking in that 5 seconds?

In trying to be terse and to the point, perhaps I did not give enough detail on what I am trying to do.

The directory-read process will indeed be very short. This short time-span is not what I am concerned about. I will have a ListBox showing the contents of the directory to the end user. She may keep this ListBox in view for hours, during which time the contents are likely to change, at least on some days. I want to update the ListBox to show the updated listing without requiring the end user to hit Refresh or Update all the time. I would also prefer not to have a timer periodically do the refresh, although that is my fallback strategy if I can't figure out how to get updated automatically by the system.

Thanks.
 
In trying to be terse and to the point, perhaps I did not give enough detail on what I am trying to do.

The directory-read process will indeed be very short. This short time-span is not what I am concerned about. I will have a ListBox showing the contents of the directory to the end user. She may keep this ListBox in view for hours, during which time the contents are likely to change, at least on some days. I want to update the ListBox to show the updated listing without requiring the end user to hit Refresh or Update all the time. I would also prefer not to have a timer periodically do the refresh, although that is my fallback strategy if I can't figure out how to get updated automatically by the system.

Thanks.

OK then, that's much clearer.

And NO, I don't think you have an option other than a timer refreshing your box. Do you realize that what you're asking for here will involve windows API's, at the very least? I've never seen such a request, and furthermore, it may very well be that it's impossible to do because you're probably delving into the threading concept of windows processes (which I doubt can be touched by any programming language).
 
Do you realize that what you're asking for here will involve windows API's, at the very least?
Yea, figured that, but did not know for sure, so I ask here.

I've never seen such a request,
Nor have I. That is why I am asking in an expert's forum.

and furthermore, it may very well be that it's impossible to do . . . .
I bet it's not. I will wait for more experts to weigh in. I am hoping to get a variety of responses after the new workweek gets under way.
 
In doing some more reading/searching, it looks like the solution is a lot easier than I originally anticipated.

Telling the system I want to watch a folder does indeed require multithreading, so that is not happening.

I can include the folder timestamp in my data structure. Then periodically (yes, my fallback strategy) query just the timestamp from the system. If it is more recent, then update the directory listing.

So, although this is where I am heading for now, other suggestions are welcomed.
 
I can include the folder timestamp in my data structure. Then periodically (yes, my fallback strategy) query just the timestamp from the system. If it is more recent, then update the directory listing.

Isn't is unreal what searching for yourself does? :D Look what you've uncovered. Did you learn something too!? :D

If so, good for you! By the way, you can query a timestamp of a file or folder by using the FSO (file system object) in vba and reading a property. There is no API required.
 

Users who are viewing this thread

Back
Top Bottom