Jump to content
ericire

Monitoring folders and files - (Moved)

Recommended Posts

Hello,
I need to monitor events regarding multiple folders and files.
For example, the arrival of a file in the google drive sync on the hard disk or changes made to files or other folders.
I tested Rmonitor which works well to monitor a single folder but in the case of google drive sync, it stops at changes made in the temporary folder used by google, and therefore does not capture the arrival of the file in the folder of destination.
Is Rmonitor configurable to capture all the changes (I did not understand the interest of the loops while 1 in the example), or do you have to multiply Rmonitor for each watched folder?
Or is there another way to capture these changes on several specific folders and files?
Rmonitor thread

https://www.autoitscript.fr/forum/viewtopic.php?p=78100#p78100
Rmonitor file
https://www.autoitscript.fr/forum/download/file.php?id=3245
example


 
#include "RepMonitor.au3" ; Configuration: ; On va surveiller mon bureau... RMonitor_SetFolder("C:\Users\Jon\Desktop\") ; ...en appelant _TestCalback à chaque évènement RMonitor_SetCallback("_TestCallback") ; ### EXEMPLE 1: Attente d'un évènement ### While 1     ; La boucle est interrompue à chaque attente     RMonitor_WaitForEvents() WEnd ; ### EXEMPLE 2: Surveillance continue ### RMonitor_StartMonitoring() While 1     ; La boucle est continue WEnd RMonitor_StopMonitoring() ; Notre callback favorite: ;   Un seul argument de type wstr ;   Prototype C: ;       void _TestCallback(const wchar_t MSG); ;       void _TestCallback(LPCWSTR MSG); (en WINAPI) Func _TestCallback($MSG)     ; 1er caractère = ID de l'évènement     Local $EventID = StringLeft($MSG, 1), _         $CompletePath = "C:\Users\Jon\" & StringTrimLeft($MSG, 1)     ; Reste = Chemin RELATIF du dossier|fichier     Static $OldName     Switch ($EventID)         Case $FILE_ACTION_ADDED             ConsoleWrite("Ajout: " & $CompletePath & @CRLF)         Case $FILE_ACTION_REMOVED             ConsoleWrite("Suppression: " & $CompletePath & @CRLF)         Case $FILE_ACTION_MODIFIED             ConsoleWrite("Modification: " & $CompletePath & @CRLF)         Case $FILE_ACTION_RENAMED_OLD_NAME             $OldName = $CompletePath         Case $FILE_ACTION_RENAMED_NEW_NAME             ConsoleWrite("Renommé: " & $OldName & " en " & $CompletePath & @CRLF)     EndSwitch EndFunc
 

 

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

no matter how you look at it, ReadDirectoryChangesW supports a single root path per thread - meaning, it can monitor only a single folder and its subfolders per thread. since AutoIt is not multithreaded, that limitation becomes process-dependent, rather than thread-dependent - meaning, one process can monitor only a single folder and its subfolders. the help file example for _WinAPI_ReadDirectoryChanges() is a perfectly workable script for a single folder, so if you rely on AutoIt alone, you need to run that script multiple times for multiple folders.

a workaround is of course as suggested above, using an external DLL.

Share this post


Link to post
Share on other sites

Like orbs implies you will need multiple processes to monitor multiple folders using _WinAPI_ReadDirectoryChanges().  But it would be kind of easy to create a single monitor script (parent) that would launch multiple  _WinAPI_ReadDirectoryChanges() processes (childs) and grab the results reading at StdoutRead (). 

Share this post


Link to post
Share on other sites

thanks for this ways
I am studying the RDC example which obviously refers to a mother file that can monitor several folders

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...