FileSystemWatcher Equivalent

How can I monitor a folder for new files as well as changes to existing files.

The program I’m integrating with writes output to a CSV file. Whenever the file changes I need to reed the file.

I’m looking for something like this.

I think MBS has a plugin that does this…

for Mac use FSEvents:
http://www.monkeybreadsoftware.net/class-fseventsmbs.shtml

for Windows:
http://www.monkeybreadsoftware.net/class-windowsdirectorywatchermbs.shtml

using MBS Xojo Plugins.

If you are checking a single file in a known location I would probably just write some code in a timer or thread to do this. Christian’s plugins would also work but those APIs are designed for detecting changes across folders and entire disks.

ok thanks

Thank @Kevin Gale , That worked like a charm.

Sub Action() if Checking then return Checking = True dim p as String = "c:\\users\\server computer\\desktop\\test.txt" dim f as new FolderItem f = GetFolderItem(p) if f <> nil and f.Exists then dim md as date = f.ModificationDate if md <> ModDate Then ModDate = f.ModificationDate dim t as TextInputStream = TextInputStream.Open(f) t.Encoding = Encodings.UTF8 TextArea1.Text = t.ReadAll t.Close end if end if checking = False End Sub

you don’t need the “new” in the dim f line.
And please pass path type to GetFolderItem as second parameter.

thanks Christian

[quote=308213:@Christian Schmitz]for Mac use FSEvents:
http://www.monkeybreadsoftware.net/class-fseventsmbs.shtml

for Windows:
http://www.monkeybreadsoftware.net/class-windowsdirectorywatchermbs.shtml

using MBS Xojo Plugins.[/quote]
Still no Linux version?

https://github.com/emcrisostomo/fswatch

Thank you.
I’m not comfortable with GitHub. I’ve searched through some of the files there, to convert it to Xojo code, but, so far, I haven’t found the needed source code. I don’t quite understand how the package is organised.

This is GPL and can’t be used in our plugin.

That means the embedded functions to monitor file system events on Linux can’t be used from Xojo plugins (or otherwise non proprietary Linux softwares)?
I’m amazed by this, then. It’s a core functionality of the OS. Is it the equivalent of Apple’s private APIs?

That means that fswatch library can’t be used due to licensing.

Of course we could write our own based on the OS functions.
And we have that already for MacOS with FSEventsMBS class and Windows with WindowsDirectoryWatcherMBS class.

Pointing to a GPL library doesn’t help. Either we need one without GPL or some bigger client funds development of a replacement.
For for most users checking a hot folder with folderitem class or FileListMBS class in a timer if enough.

Ah, yes, the library alone, not the OS provided functions. Makes more sense then.

[quote=476410:@Christian Schmitz]Of course we could write our own based on the OS functions.
And we have that already for MacOS with FSEventsMBS class and Windows with WindowsDirectoryWatcherMBS class.[/quote]
That’s actually why I always wonder why the MBS plugin supports FS events in Mac and Windows but not in Linux, knowing all three exist.

Is the FS events implementation in Linux harder to include than the counterparts of other systems? Or more expensive?
I’m failing to understand why one would want FS events in Mac and Windows but less on Linux (appart from the fact that Linux is perhaps less used, but the point of Xojo is to join all three platforms to the “relative” same level, right?).

As would probably be the same for Mac and Windows (defeating the fact to have FS events for them in the first place).
Is the difference because you include functions in the MBS plugin only when “really” needed? What actually makes the FS events in Linux from being excluded off the plugin?
Thank you.

We add things to MBS Plugin for this reasons:

  • a customer orders it as contract work
  • we need it ourselves for a project
  • it is quick change and makes a client happy
  • it makes a good bullet point for the next release.

And we keep a wish list where we count how often someone asked for it.

So folder watching for Linux could come, but it’s not a priority for us as Geoff would say.

[quote=476415:@Christian Schmitz]We add things to MBS Plugin for this reasons:

  • a customer orders it as contract work
  • we need it ourselves for a project
  • it is quick change and makes a client happy
  • it makes a good bullet point for the next release.

And we keep a wish list where we count how often someone asked for it.

So folder watching for Linux could come, but it’s not a priority for us as Geoff would say.[/quote]
Thanks for your answer. You may add me to the wish list, then ?.

Here’s some linux code https://github.com/codeplea/fsghost/blob/master/main.c#L116 showing how to use inotify

Thank you; I’ll look to convert this code.

and some light reading https://www.linuxjournal.com/article/8478 :slight_smile: