Jump to content

RDC UDF (ReadDirectoryChanges Wrapper)


Yashied
 Share

Recommended Posts

  • 1 year later...

I found and repaired a tiny problem with RDC.au3 and have attached a zip file with the correction (all other files are exactly as provided by @Yashied 's great UDF).

This is the one small problem I corrected:

  1. The UDF function _RDC_GetData() originally did not return the output data array in the order the documentation specified; i.e., element "[n][0]" used to hold the filename and "[n][1]" used to return the change type.  Now the function returns the data as specified.

This was a trivial correction and should not detract from Yasheid's fine code and extremely useful UDF.

 

By the way, to those who haven't used this and similar UDFs that make use of Microsoft's "ReadDirectoryChangesW" function, please be aware that you will see duplicate notifications of most (or all?) changes. For example, if a new file is created in a directory being watched, you will see two identical FILE_ACTION_ADDED notifications, both with the same filename...

 

General RDC v1.1 Test Script with GUI.au3

RDC_1.1.zip

Edited by Mbee
Posted RDC_1.1.zip & example test script
Link to comment
Share on other sites

On 11/5/2016 at 3:24 PM, Mbee said:

I found and repaired a tiny problem

I did not see the problem in v1.0 <snip>

It's all there, v1.1 just doesn't seem to work

Edited by argumentum
revised again

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

  • 2 weeks later...
On 11/11/2016 at 10:21 PM, argumentum said:

I did not see the problem in v1.0 <snip>

It's all there, v1.1 just doesn't seem to work

Please forgive the delay in responding...

I apologize for any etiquette violations or unintended toe-stepping-on, good sir!  But I'd like more information concerning your reply, if you'd be so kind. Are you saying that version 1.0 DID return the type in [n][0] and the filename in [n][1], or what?  Because v1.0 definitely returned them in the order opposite to what the documentation said when I used it. v1.1 returns [n][0] = type, [n][1] = filename, as documented.

Please let me know precisely what you mean when you say "v1.1 just doesn't seem to work".

Thanks!

Link to comment
Share on other sites

7 hours ago, Mbee said:

I apologize for any etiquette violations or unintended toe-stepping-on

no toes here. The code you posted, I've tried then, and did not work at the time. Not my code, no pride, even if it was my code, just a technical view. Have no time this week to truly test. I'll give it a better try later and compare the results. I may have to write a script that writes very fast and see what you mean. I use mailslots as an IPC to not slow down this code, so I get the results in another script reading the mailsot.

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

On 11/22/2016 at 0:15 AM, argumentum said:

Have no time this week to truly test.

Local $n
Local $t = @MIN&@SEC
For $n = 1 To 100
;~  Sleep($n * 10)
    FileWriteLine(@ScriptDir&'\~TEST~\testFastWrite'&$t&'_'&$n&'.txt',"delete, this just a test."&@CRLF)
Next

@Mbee , I've runned this and checked the original code's result. Could not find anything out of sequence.

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

  • 2 weeks later...

hi i  have a questions about  RDC 1.1   https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=52633

i tryed to run a example  file RDC_Ex_Simple (Notification).au3   but where is a path for monitoring a file/folder??

i used also a GUI , i choice  a folder , and  after create and modify and remove a file  txt , inside the folder ,  but  not appear nothing in gui o_O

Link to comment
Share on other sites

  • Moderators

faustf,

Have you downloaded the DLL file? And where is code you wrote to test? Help us to help you.

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

o thankz so much @Melba23  at end  i think i  have  understund somthing  i modify a example script like  this and i saw the script work  , more or  less for my case

#Include <APIConstants.au3>
#Include <RDC.au3>

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

_RDC_OpenDll()
If @Error Then
    ConsoleWrite('Error: _RDC_OpenDll() - ' & @Error & @CR)
    Exit
EndIf

Global $hWnd = GUICreate('')
Global $aDir[3]

For $i = 0 To 2
    $aDir[$i] = @ScriptDir & '\~TEST' & ($i + 1) & '~'
    If Not FileExists($aDir[$i]) Then
        DirCreate($aDir[$i])
    EndIf
Next

GUIRegisterMsg($WM_RDC, 'WM_RDC')

For $i = 0 To 2
    _RDC_Create("C:\Users\utente\Desktop\", 1, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), 0, $hWnd)
    If @Error Then
        ConsoleWrite('Error: _RDC_Create() - ' & @Error & ', ' & @Extended & @CR)
        Exit
    EndIf
Next

While 1
    Sleep(1000)
WEnd

Func WM_RDC($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $aData = _RDC_GetData($lParam)

    If @Error Then

        ; Do something because notifications will not come from this thread!
        ConsoleWrite('Error: _RDC_GetData() - ' & @Error & ', ' & @Extended & ', ' & _RDC_GetDirectory($lParam) & @CR)

        _RDC_Delete($lParam)
        Return 0
    EndIf
    For $i = 1 To $aData[0][0]
        ConsoleWrite($aData[$i][1] & ' - ' & _RDC_GetDirectory($lParam) & '\' & $aData[$i][0] & @CR)
    Next
    Return 0
EndFunc   ;==>WM_RDC

 

 

Link to comment
Share on other sites

hi guys  i did do a little modify , for understund how  work the  script RDC_EX_Simple.au3

but i have a problem , i run the script it  works perfect  but  put  my cpu at 100% usage , probably i  did do some error

#Include <APIConstants.au3>
#Include <RDC.au3>

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

_RDC_OpenDll()
If @Error Then
    ConsoleWrite('Error: _RDC_OpenDll() - ' & @Error & @CR)
    Exit
EndIf

Global $hWnd = GUICreate('')
Global $aDir[3]

For $i = 0 To 2
    $aDir[$i] = @ScriptDir & '\~TEST' & ($i + 1) & '~'
    If Not FileExists($aDir[$i]) Then
        DirCreate($aDir[$i])
    EndIf
Next

GUIRegisterMsg($WM_RDC, 'WM_RDC')

For $i = 0 To 2
    _RDC_Create("C:\Users\utente\Desktop", 1, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), 0, $hWnd)
    If @Error Then
        ConsoleWrite('Error: _RDC_Create() - ' & @Error & ', ' & @Extended & @CR)
        Exit
    EndIf
Next

While 1
    Sleep(1000)
WEnd

Func WM_RDC($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $aData = _RDC_GetData($lParam)

    If @Error Then

        ; Do something because notifications will not come from this thread!
        ConsoleWrite('Error: _RDC_GetData() - ' & @Error & ', ' & @Extended & ', ' & _RDC_GetDirectory($lParam) & @CR)

        _RDC_Delete($lParam)
        Return 0
    EndIf
    For $i = 1 To $aData[0][0]
        ConsoleWrite($aData[$i][1] & ' - ' & _RDC_GetDirectory($lParam) & '\' & $aData[$i][0] & @CR)
Select
    Case $aData[$i][0] = 1 ; è crea file
        ; se è passatoda qui non deve attiva il punto 3
    MsgBox(0,'Info','Lancio controllo formato')
            ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Case $aData[$i][0] = 2 ; è cancella file
        MsgBox(0,'Info','Lancio ftpbox')
                ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Case $aData[$i][0] = 3 ; è modifica file
        MsgBox(0,'Info','Lancio controllo formato modifica file')
        ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

EndSelect

    ;   ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)
    Next
    Return 0
EndFunc   ;==>WM_RDC

someone can help me?? thankz again :)

 

Link to comment
Share on other sites

7 hours ago, faustf said:

i run the script it  works perfect  but  put  my cpu at 100% usage

MsgBox(0,'Info','Lancio controllo formato')

is a blocking thing. Do not use msgbox in this script. Anything that is called by 

GUIRegisterMsg

should not be slow. Make a global variable that changes to, lets say, to 1, then from the main loop you can do the MsgBox or what not.

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

hi @argumentum  i remove a msgbox   but i  have the same effect  work  but put  100% cpu load

#Include <APIConstants.au3>
#include <GDIPlus.au3>
#Include <RDC.au3>

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

_RDC_OpenDll()
If @Error Then
    ConsoleWrite('Error: _RDC_OpenDll() - ' & @Error & @CR)
    Exit
EndIf

Global $hWnd = GUICreate('')
Global $aDir[3]

For $i = 0 To 2
    $aDir[$i] = @ScriptDir & '\~TEST' & ($i + 1) & '~'
    If Not FileExists($aDir[$i]) Then
        DirCreate($aDir[$i])
    EndIf
Next

GUIRegisterMsg($WM_RDC, 'WM_RDC')

For $i = 0 To 2
    _RDC_Create("C:\Users\utente\Desktop", 1, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), 0, $hWnd)
    If @Error Then
        ConsoleWrite('Error: _RDC_Create() - ' & @Error & ', ' & @Extended & @CR)
        Exit
    EndIf
Next

While 1
    Sleep(1000)
WEnd

Func WM_RDC($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $aData = _RDC_GetData($lParam)

    If @Error Then

        ; Do something because notifications will not come from this thread!
        ConsoleWrite('Error: _RDC_GetData() - ' & @Error & ', ' & @Extended & ', ' & _RDC_GetDirectory($lParam) & @CR)

        _RDC_Delete($lParam)
        Return 0
    EndIf
    For $i = 1 To $aData[0][0]
        ConsoleWrite($aData[$i][1] & ' - ' & _RDC_GetDirectory($lParam) & '\' & $aData[$i][0] & @CR)
Select
    Case $aData[$i][0] = 1 ; è crea file
        ; se è passatoda qui non deve attiva il punto 3
    ;MsgBox(0,'Info','Lancio controllo formato')
            ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Case $aData[$i][0] = 2 ; è cancella file
        ;MsgBox(0,'Info','Lancio ftpbox')
                ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Case $aData[$i][0] = 3 ; è modifica file
        ;MsgBox(0,'Info','Lancio controllo formato modifica file')
        ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

EndSelect
Sleep(100)
    ;   ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)
    Next
    Return 0
EndFunc   ;==>WM_RDC

 

Link to comment
Share on other sites

i tryed in this mode  and  i saw  only  69% percent of usage of cpu  , i think is correct  , you  confirme  that???

#Include <APIConstants.au3>
#include <GDIPlus.au3>
#Include <RDC.au3>

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

_RDC_OpenDll()
If @Error Then
    ConsoleWrite('Error: _RDC_OpenDll() - ' & @Error & @CR)
    Exit
EndIf

Global $hWnd = GUICreate('')
Global $aDir[3]
Global $iGResult
For $i = 0 To 2
    $aDir[$i] = @ScriptDir & '\~TEST' & ($i + 1) & '~'
    If Not FileExists($aDir[$i]) Then
        DirCreate($aDir[$i])
    EndIf
Next

GUIRegisterMsg($WM_RDC, 'WM_RDC')

For $i = 0 To 2
    _RDC_Create("C:\Users\utente\Desktop", 1, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), 0, $hWnd)
    If @Error Then
        ConsoleWrite('Error: _RDC_Create() - ' & @Error & ', ' & @Extended & @CR)
        Exit
    EndIf
Next

While 1
    Sleep(1000)
WEnd

Func WM_RDC($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $aData = _RDC_GetData($lParam)

    If @Error Then

        ; Do something because notifications will not come from this thread!
        ConsoleWrite('Error: _RDC_GetData() - ' & @Error & ', ' & @Extended & ', ' & _RDC_GetDirectory($lParam) & @CR)

        _RDC_Delete($lParam)
        Return 0
    EndIf
    For $i = 1 To $aData[0][0]
        ConsoleWrite($aData[$i][1] & ' - ' & _RDC_GetDirectory($lParam) & '\' & $aData[$i][0] & @CR)
$iGResult=$aData[$i][0]
#cs
Select
    Case $aData[$i][0] = 1 ; è crea file
        ; se è passatoda qui non deve attiva il punto 3
    ;MsgBox(0,'Info','Lancio controllo formato')
            ;ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Case $aData[$i][0] = 2 ; è cancella file
        ;MsgBox(0,'Info','Lancio ftpbox')
            ;   ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Case $aData[$i][0] = 3 ; è modifica file
        ;MsgBox(0,'Info','Lancio controllo formato modifica file')
        ;ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

EndSelect
#ce
    ;   ConsoleWrite(_RDC_GetDirectory($lParam) & '\' &$aData[$i][1] & @CR)

    Next
    ConsoleWrite($iGResult)
    Return 0
EndFunc   ;==>WM_RDC

 

Link to comment
Share on other sites

hi   where  is a list of error , my  prog  return this   error

Error: _RDC_GetData() - 5, 0, 0
Error: _RDC_GetData() - 7, 1, E:\_GESTIONALE_NEW\WEB-SITE\eBay\PUBLICAZIONI\FOTO\


sorry i not saw  ,  i answer me  :)

 

 Error codes:

        @Error:

        0 - No error
        1 - DLL not loaded or already loaded
        2 - DLL not found
        3 - Incompatible DLL version
        4 - Unable to load DLL
        5 - Invalid parameter(s)
        6 - Directory not found
        7 - DllCall() error

Edited by faustf
Link to comment
Share on other sites

questions  i notice   if  in script 

#include <APIConstants.au3>
#include <GDIPlus.au3>

#include "RDC.au3"

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

_RDC_OpenDll()
If @error Then
    ConsoleWrite('Error: _RDC_OpenDll() - ' & @error & @CR)
    Exit
EndIf

Global $hWnd = GUICreate('')
Global $aDir[3]
Global $iGResult
For $i = 0 To 2
    $aDir[$i] = @ScriptDir & '\TEMP\~TEST' & ($i + 1) & '~'
    If Not FileExists($aDir[$i]) Then
        DirCreate($aDir[$i])
    EndIf
Next

GUIRegisterMsg($WM_RDC, 'WM_RDC')

For $i = 0 To 2
    _RDC_Create("C:\Users\utente\Desktop", 1, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), 0, $hWnd)
    If @error Then
        ConsoleWrite('Error: _RDC_Create() - ' & @error & ', ' & @extended & @CR)
        Exit
    EndIf
Next

While 1
    Sleep(1000)
WEnd

Func WM_RDC($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $aData = _RDC_GetData($lParam)

    If @error Then

        ; Do something because notifications will not come from this thread!
        ConsoleWrite('Error: _RDC_GetData() - ' & @error & ', ' & @extended & ', ' & _RDC_GetDirectory($lParam) & @CR)

        _RDC_Delete($lParam)
        Return 0
    EndIf
    For $i = 1 To $aData[0][0]
        $iGResult = $aData[$i][0]
    Next
    ConsoleWrite($iGResult)
    Return 0
EndFunc   ;==>WM_RDC

i use  C:\Users\utente\Desktop  work good  but if  i use  attached hdd network(E:\_GESTIONALE_NEW\WEB-SITE\) , not  work and  give me error 5 , how is possible change them??? 

thankz

Link to comment
Share on other sites

This script works for me with a network drive.

But there a numerous errors with it. You don't need the For loops in your script, and you don't even need the entire contents of the first For loop at all. Second, it looks like you smashed the 2 example scripts together without understanding what each one is to be used for, and missing parts of each that might make the issue you're having happen.

 

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

$WM_RDC = 0xA000 is a user defined message code in the range 0x8000 through 0xBFFF which are available for applications to use as private messages. See WM_USER.

0xA000 is (except that it is easy to remember) a random number in this range.

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...