Jump to content

FileSystemMonitor UDF


seangriffin
 Share

Recommended Posts

  • 2 weeks later...
On 1/7/2019 at 4:37 PM, argumentum said:

Hi :)
What you are been asked is your code, as anyone can get the UDF.  So cough up your script.

Sorry, English isn't my native language, so I don't know what you mean with "So cough up your script".

When you read my posts starting from ...

...I am not sure how to get a running UDF file, because to downloadable UDF file is not running, as far as I can evaluate this. It seems to me, that the Windows 10 API has changed which must be adjusted within the UDF, which wasn't possible to me and which is the reason why I am started writing posts here --> To get informed if there is an updated and working UDF file or to get help with the adjusting of the UDF.

My problem is, that I don't have any experience with the DllStruct... calls / function of AutoIt, as i wrote in previous posts...

So, back to starting post of me:

         Is there a UDF version available which works on current windows 10 systems with current AutoIt version 3.3.14.5?

 

Link to comment
Share on other sites

3 hours ago, Taneeda said:

so I don't know what you mean with "So cough up your script".

Meaning: Post your script :)

you could use _WinAPI_FindFirstChangeNotification.htm or something from the help file. In so far, nothing has been perfect in my experience.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

The attached zip file contains my current working copy...

On 1/18/2019 at 3:55 PM, argumentum said:

you could use _WinAPI_FindFirstChangeNotification.htm or something from the help file. In so far, nothing has been perfect in my experience.

...I will try to use/integrate this function, thank you very much for this hint, sounds like it could be an alternative to the UDF.

au3_scripts.zip

 

--- UPDATE ---

 

After some research and different tries, I found WinAPI_ReadDirectoryChanges(), but the usage resulted in an execution problem, which is explained in...

...and solved by...

At the moment, this nice RDC UDF solved my problems and usage of FileSystemMonitor UDF isn't necessary anymore.

Edited by Taneeda
Link to comment
Share on other sites

  • 1 year later...

This is a very brilliant UDF. 👍

I am looking for an additional feature to monitor changes on a USB attached drive beginning in the root of that drive and monitoring all changes on the drive not "only" in a given folder. I have had a look into the UDF but have not found something that would help me in this matter.

Has someone of you maybe got an idea how to monitor the whole given drive for changes and also list this changes (filenames)?

Many thanks in advance,
best regards

TheDude

Link to comment
Share on other sites

  • Moderators

TheDude69,

All I have ever managed to do with the $sShellMon_Path parameter for _FileSysMonSetup is to get the "Drive free space has changed|SHCNE_FREESPACE" message whenever a file is added/deleted anywhere on the drive - but never any details on the file itself or its location.

I suppose you could use _FileListToArrayRec each time to look for changes, but it is a bit long-winded. Sorry i cannot be any more help.

M23

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

 

Link to comment
Share on other sites

@TheDude69 You can use _WinAPI_ReadDirectoryChanges with a USB attached drive (juste tested and working fine).  Check help file for the example.  Do not forget to set $bSubtree to 1 if you want to check the whole drive.  Be aware that the example is used in a blocking mode.  You can modify it to work in asynchronous mode, check MSDN for more explanations. 

edit : I did not read the whole thread, I was just answering your question.  I see there is sort of a discussion around this API above.  Just want to let you know that you do not need to create process threadS to make it work.  It is well explained in MSDN.

Edited by Nine
Link to comment
Share on other sites

  • 1 year later...

I'm using the provided unmodified example and the thing is calling the function multiple times. Meaning one file gets dropped in the specified folder and _FileSysMonDirEventHandler gets called 3 times....prints the file on the listview twice. Am I the only one that experienced this? I tried to widdle the script down, but got nowhere with eliminating this issue. Using win10 64Bit. Any help?

Thanks.

 

edit:

I fixed it by doing this to _FileSysMonDirEventHandler() and it seems to be working fine so far...but I don't think I should have to do that.

If $Filename <> $NewFile Then
                ;MsgBox(0,$NewFile,$Filename)
                _FileSysMonActionEvent(0, DllStructGetData($tFNI, "Action"), $Filename)
                $NewFile = $Filename
            EndIf

 

Edited by Champak
Link to comment
Share on other sites

  • Moderators

Champak,

Several events can indeed be fired by a single action with this UDF - this is the list I check for when using this UDF:

Switch $event_type

        Case 0 ; Directory event

            ConsoleWrite($event_id & @CRLF)

            Switch $event_id
                Case 1
                    $sEvent = "file added to the directory|FILE_ACTION_ADDED"
                Case 2
                    $sEvent = "file removed from the directory|FILE_ACTION_REMOVED"
                Case 3
                    $sEvent = "file was modified|FILE_ACTION_MODIFIED"
                Case 4
                    $sEvent = "file was renamed old name|FILE_ACTION_RENAMED_OLD_NAME"
                Case 5
                    $sEvent = "file was renamed new name|FILE_ACTION_RENAMED_NEW_NAME"
            EndSwitch

        Case 1 ; Shell event

            Switch $event_id
                Case 0x00000001
                    $sEvent = "Non-folder item name changed|SHCNE_RENAMEITEM"
                Case 0x00000002
                    $sEvent = "Non-folder item created|SHCNE_CREATE"
                Case 0x00000004
                    $sEvent = "Non-folder item deleted|SHCNE_DELETE"
                Case 0x00000008
                    $sEvent = "Folder created|SHCNE_MKDIR"
                Case 0x00000010
                    $sEvent = "Folder removed|SHCNE_RMDIR"
                Case 0x00000020
                    $sEvent = "Storage media inserted into a drive|SHCNE_MEDIAINSERTED"
                Case 0x00000040
                    $sEvent = "Storage media removed from a drive|SHCNE_MEDIAREMOVED"
                Case 0x00000080
                    $sEvent = "Drive removed|SHCNE_DRIVEREMOVED"
                Case 0x00000100
                    $sEvent = "Drive added|SHCNE_DRIVEADD"
                Case 0x00000200
                    $sEvent = "Local computer folder shared via the network|SHCNE_NETSHARE"
                Case 0x00000400
                    $sEvent = "Local computer folder not shared via the network|SHCNE_NETUNSHARE"
                Case 0x00000800
                    $sEvent = "Item or folder attributes have changed|SHCNE_ATTRIBUTES"
                Case 0x00001000
                    $sEvent = "Folder content has changed|SHCNE_UPDATEDIR"
                Case 0x00002000
                    $sEvent = "Folder or non-folder has changed|SHCNE_UPDATEITEM"
                Case 0x00004000
                    $sEvent = "Computer disconnected from server|SHCNE_SERVERDISCONNECT"
                Case 0x00008000
                    $sEvent = "System image list image has changed|SHCNE_UPDATEIMAGE"
                Case 0x00010000
                    $sEvent = "Not used|SHCNE_DRIVEADDGUI"
                Case 0x00020000
                    $sEvent = "Folder name has changed|SHCNE_RENAMEFOLDER"
                Case 0x00040000
                    $sEvent = "Drive free space has changed|SHCNE_FREESPACE"
                Case 0x0002381F
                    $sEvent = "SHCNE_DISKEVENTS"
                Case 0x0C0581E0
                    $sEvent = "SHCNE_GLOBALEVENTS"
                Case 0x7FFFFFFF
                    $sEvent = "SHCNE_ALLEVENTS"
                Case 0x80000000
                    $sEvent = "SHCNE_INTERRUPT"
            EndSwitch
    EndSwitch

So you will need to do some detective work to check exactly which events were triggered and decide whether to action or ignore them. All I needed to do when I have used this UDF was to check for the creation of a new file, which simplified the problem considerably.

M23

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

 

Link to comment
Share on other sites

That's the thing, it's the same action hitting twice and then a different one. Directory event File Added hits twice, and then something else with eventID 3 that wasn't incorporated in Directory Events.

This is what the unmodified example writes to console

0|1|Folder_Monitor.au3
adding file / folder Folder_Monitor.au3
1|0x04000000|
1|0x04000000|
1|0x00040000|F
1|0x04000000|
0|1|Folder_Monitor.au3
adding file / folder Folder_Monitor.au3
0|3|Folder_Monitor.au3

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...