BatMan22 Posted January 17, 2021 Share Posted January 17, 2021 (edited) Hi guys, I'm just using _WinAPI_ReadDirectoryChanges to monitor a network folder.. but the buffer size seems to be creating some issues where the script is slow / non-responsive a lot of the time. I BELIEVE it's attributed to the buffer size anyways. From the help file, and experience, buffer size must be LESS then 64k but buffer size being less then 64k seems to also be the cause as mentioned in the help file..? Ideas? So Damned if you do, damned if you don't? Quote from them help file: To prevent the crash of the script, use the buffer at least not less than 64 KB. If the buffer is greater than 64 KB and the application is monitoring a directory over the network, the function fails. This is due to a packet size limitation with the underlying file sharing protocols. #include <APIFilesConstants.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> #include <WinAPIFiles.au3> #include <WinAPIMem.au3> Global $g_sPath = "\\server\LIMS\Data Import\CO" Local $hDirectory = _WinAPI_CreateFileEx($g_sPath, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS) If @error Then ;~ MsgBox(0,0,0) _WinAPI_ShowLastError('', 1) EndIf Local $pBuffer = _WinAPI_CreateBuffer(64000) Local $aData While 1 $aData = _WinAPI_ReadDirectoryChanges($hDirectory, $FILE_NOTIFY_CHANGE_CREATION, $pBuffer, 64000, 1) If Not @error Then _ArrayDisplay($aData, '_WinAPI_ReadDirectoryChanges') Else MsgBox(0,0,0) _WinAPI_ShowLastError('', 1) EndIf WEnd Edited January 17, 2021 by BatMan22 Link to comment Share on other sites More sharing options...
Nine Posted January 17, 2021 Share Posted January 17, 2021 I would be tempted to try an asynchronous approach using this function in overlapped mode. I vaguely remember someone testing it and affirming it was more robust over a network. But I could be wrong, so you will need to test it in your environment. On the other hand, since it is non-blocking, it might be easier for the function to return normally if the directory failed to be read. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BatMan22 Posted January 18, 2021 Author Share Posted January 18, 2021 @Nine And.. you lost me. You're talking about a function that does not currently exist in autoit, am I correct? "_WinAPI_ReadDirectoryChangesW" is not a function, so is that something I would need to add to my WinAPIFiles.au3 include? FindBatch() Func FindBatch() Local $hDirectory = _WinAPI_CreateFileEx($PlateLayoutLocations, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS) If @error Then _WinAPI_ShowLastError('', 1) EndIf Local $pBuffer = _WinAPI_CreateBuffer(64000) Local $aData While 1 $aData = _WinAPI_ReadDirectoryChanges($hDirectory, $FILE_NOTIFY_CHANGE_CREATION, $pBuffer, 64000, 1) If Not @error Then If StringInStr($aData[1][0], "LunaMultiplex Plate Layout_") Then ConsoleWrite(@CR & "New Plate Layout Found! " & $aData[1][0] & @CR) WinWait("Microsoft Access", "To CV Layout done.") WinActivate("Microsoft Access", "To CV Layout done.") Send("{Enter}") $c = MsgBox(4, 0, "YES OR NO?") If $c = 6 Then $PlateName = $aData[1][0] $batchID = StringTrimLeft($aData[1][0], 27) $batchID = StringTrimRight($batchID, 4) ConsoleWrite($batchID) PrepPate() EndIf EndIf Else _WinAPI_ShowLastError('', 1) EndIf WEnd EndFunc ;==>FindBatch Link to comment Share on other sites More sharing options...
Nine Posted January 18, 2021 Share Posted January 18, 2021 51 minutes ago, BatMan22 said: You're talking about a function that does not currently exist in autoit, am I correct? True. It is more complex than the one you are using but I think it is worth a try. Search the forum, I remember someone posting a working example of it. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BatMan22 Posted January 20, 2021 Author Share Posted January 20, 2021 @Nine I think what you're talking about is linked below, thanks! You're a life saver, I will give this a shot. Responding for future people who search for a solution for this. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now