Lazarus

Programming => General => Topic started by: superc on January 02, 2019, 02:39:00 pm

Title: Notify file change
Post by: superc on January 02, 2019, 02:39:00 pm
Hello,
I must receive a notification in my program when a specific file into a specific directory is changed;
the program can run in both Windows and Raspbian (raspberry)  and can receive data in a specific directory and append data in only one static file.
I have seen a document of Michaƫl Van Canneyt "Displaying and Watching directories using Lazarus" and it's of 2011 and my question is what is the best method in 2018/2019 for
implementing in a cross-platform application for watching file in Lazarus?
Thanks in advance.
Title: Re: Notify file change
Post by: fred on January 02, 2019, 03:39:36 pm
I have never used it but this checks every second the file size/date.

https://github.com/Alexey-T/ATFileNotif-Lazarus

On windows there are better ways to do it but at least this should be cross-platfom since only basic operations are used.
Title: Re: Notify file change
Post by: superc on January 02, 2019, 04:51:13 pm
Mhhh, it use a ttimer for check .... Of the series: if you do not have anything better you go to sleep with your wife.
Title: Re: Notify file change
Post by: metis on January 02, 2019, 05:25:57 pm
@superc

Let's see, if the 'Double Commander' knows more than Wives: https://sourceforge.net/p/doublecmd/wiki/Download/ (https://sourceforge.net/p/doublecmd/wiki/Download/)
-> Download the Source and take a Look at 'src\platform\uDriveWatcher.pas'

I'm just writing a simple FileBrowser to manage Audio-/VideoFiles, but didn't check that Unit yet - maybe it's what You're Looking for.

 :)
Title: Re: Notify file change
Post by: sstvmaster on January 02, 2019, 07:47:51 pm
Hi, i use this, see attachment, Windows only.

Title: Re: Notify file change
Post by: jamie on January 02, 2019, 11:19:40 pm
sstvmaster, I think I asked you this before?

What does the SSTV-Master mean? Slow Scan Tv comes to mind. :D
Title: Re: Notify file change
Post by: sstvmaster on January 03, 2019, 11:16:42 am
@jamie, thats right.
Title: Re: Notify file change
Post by: mercurhyo on January 03, 2019, 11:39:02 pm
https://forum.lazarus.freepascal.org/index.php?topic=37415.0 (https://forum.lazarus.freepascal.org/index.php?topic=37415.0)
Title: Re: Notify file change
Post by: mica on January 04, 2019, 02:31:53 am
this is the link to the unit metis recommended


https://github.com/cooljeanius/doublecmd/blob/master/src/platform/udrivewatcher.pas

this should fit for you
Title: Re: Notify file change
Post by: superc on January 04, 2019, 09:52:37 am
@mercurhyo
wow, is perfect !
Thanks  :D
Title: Re: Notify file change
Post by: jamie on January 04, 2019, 11:35:40 pm
From what I can see that only monitors a Device change, which means It only notifies you of a
a drive being inserted ect. It does not watch a file in a specific path..

Title: Re: Notify file change
Post by: metis on January 09, 2019, 06:36:51 pm
I'm quite sure, the 'Double Commander' does anything You want with Drives, Dirs and Files.
Simply download the Binary and check out the running App.
Then take the (whole) Source and see how it's done - it's all open Source :)
Title: Re: Notify file change
Post by: jamie on January 09, 2019, 10:43:43 pm
For windows you need to use "FindFirstChangeNotification", then FindNextChangeNotification
and finally the FindCloseChangeNotification to end it,


 basically  you specify the file you watch to watch or Directory etc...

 this is a blocking process so you do need to so this within a thread...

Title: Re: Notify file change
Post by: mercurhyo on January 10, 2019, 04:17:09 pm
@superc
 :D :P ;)
Title: Re: Notify file change
Post by: mercurhyo on January 10, 2019, 04:23:33 pm
feel free to thank @Wosi who made excellent crossplatform work  O:-) with a cool API to watch files'n'dirs
Title: Re: Notify file change
Post by: benohb on January 13, 2019, 03:36:54 am
raspberry = linux
https://www.freepascal.org/docs-html/rtl/linux/inotify_add_watch.html
TinyPortal © 2005-2018