Welcome! Log In Create A New Profile

Advanced

Monitoring a folder for changes

Posted by Malc 
Malc
Monitoring a folder for changes
September 08, 2008 11:21AM
OK, I've done this in other languages, either directly by polling with timers, or using the API and monitoring FindFirstChangeNotification. etc.


I also see there is a FileSystemWatcher object in .NET


Anyone done this in WinDev and come up with the 'best' way?

Cheers

Malc
Alexandre Leclerc
Re: Monitoring a folder for changes
September 08, 2008 06:41PM
Hi Malc,

See LST 71 p.8 for a full example including a component that does all the thing. It uses the function DotNetDelegate (WD12).

Regards.
Malc
Re: Monitoring a folder for changes
September 09, 2008 04:22PM
Thanks Alexandre.

Unfortunately an LST subscription is still on the to do list and I'm not entirely convinced how useful it would be with my appalling lack of foreign language skills.

That said, where do you go to subscribe?


Cheers


Malc


Alexandre Leclerc
Re: Monitoring a folder for changes
September 09, 2008 09:10PM
Hi Malc,

Yep, if you do not understand French, it will be usefull at almost nothing. Except if the code gives you some clues.

To get the LST, just ask a distributor (at the top of this forum) about it, or PC Soft directly.

I would try to ask them if you can get this example code to help you. The LST Licence does not allow me to send you the example, but it goes along these lines...

I guess that you can get all this information from the .net framework (look at the C# example for clarity... it's pretty much the same in WinDev): [msdn.microsoft.com]

With that documentation you'll be able to figure out all the other properties of the watcher. But to help you out a bit, here is some WD code to get you started.

clWatcher is FileSystemWatcher() // create the system watcher class (uses .net class)

// add the delegates to the class
clWatcher:add_Created(DotNetDelegate(MyEventAdd,"FileSystemEventHandler"))
clWatcher:add_Renamed(DotNetDelegate(MyEventRen,"RenamedEventHandler"))

You can do it the long way, like:
EventHandlerAdd is FileSystemEventHandler dynamic // or RenamedEventHandler for rename
//then declare the .net delegates:
EventHandlerAdd = DotNetDelegate(MyEventAdd,"FileSystemEventHandler") // or "RenamedEventHandler" for rename
// then add these handler to the class
clWatcher:add_Created(EventHandlerAdd) // there is :add_Created, :add_Changed, :add_Deleted, :add_Renamed

Again, see "DotNetDelegate" in WD help for the weird "add_" thing.

Finally, declare your events procedures:

PROCEDURE MyEventRen(Object, Event)

sNew is string = Event:FullPath // in all the cases (other events) the file/folder path is stored here
sOld is string = Event:OldFullPath // in the case of renaming, the old file/folder path is stored here

IF fFileExist(Event:FullPath) = False THEN
// Folder renaming
ELSE
// File renaming
END


Finally,
clWatchertongue sticking out smileyath = "C:\MyFolder\" // set directory to watch
clWatcher:EnableRaisingEvents = True // start watching
// and later...
clWatcher:EnableRaisingEvents = False // stop watching

I hope this will help you setup the folder watching.

If you can get a hand on the LST example, it will certainly help you figure out some details.

Best regards.



Edited 1 time(s). Last edit at 09/09/2008 09:12PM by Alexandre Leclerc.
Malc
Re: Monitoring a folder for changes
September 10, 2008 10:40AM
Hi Alexandre

Thanks for a very complete reply

Cheers

Malc

Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: