Buster2000 Posted December 25, 2019 Share Posted December 25, 2019 Hi - I have an app which which writes files to a folder and once those files have been written it moves on to another task. I have some of this automated using AutoIT - but I'm looking for help with a loop or a pause so AutoIT waits for the files to finish writing to a folder before moving onto the next AutoIT command. Can someone help guide me down the right path on this? I've investigated many methods but have been unable to find much in the forums. Link to comment Share on other sites More sharing options...
Musashi Posted December 25, 2019 Share Posted December 25, 2019 Have a look at : FileFlush Your script would also be helpful for further support . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
junkew Posted December 25, 2019 Share Posted December 25, 2019 https://www.autoitscript.com/autoit3/docs/functions/FileGetSize.htm Check filesize for a certain number of seconds not growing in size. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Buster2000 Posted December 26, 2019 Author Share Posted December 26, 2019 Thanks for your replies. After further investigation I found DirGetSize is the way to go. My next question is how do I put DirGetSize into a loop so the script pauses while $iSize is changing in dize, until I've had 30 seconds of $iSize not changing before moving onto the next command? I've included my script below. Thanks in advance. Quote #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> DirSize() Func DirSize() Local $iSize = DirGetSize("C:\Temp", $DIR_EXTENDED) If Not @error Then MsgBox($MB_SYSTEMMODAL, "", "Size(Bytes): " & $iSize[0] & @CRLF _ & "Files: " & $iSize[1] & @CRLF) EndIf EndFunc ; Next Command WinWaitActive("Desktop") Sleep(3000) Send("{Runscript.exe}") Send("{Enter}") Link to comment Share on other sites More sharing options...
Nine Posted December 26, 2019 Share Posted December 26, 2019 Try this : #include <Constants.au3> CheckDirSize("C:\Temp") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error reading directory") ; do the things you need to do here Func CheckDirSize($sFolder) Local $iSize = DirGetSize($sFolder) If @error Then Return SetError(1) Local $hTimer = TimerInit(), $iNewSize While True Sleep(1000) $iNewSize = DirGetSize($sFolder) If $iSize = $iNewSize Then If TimerDiff($hTimer) > 30 * 1000 Then Return Else $iSize = $iNewSize $hTimer = TimerInit() EndIf WEnd EndFunc ;==>CheckDirSize “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...
Danp2 Posted December 26, 2019 Share Posted December 26, 2019 A few observations -- I hope that the c:\temp directory is just an example. Otherwise, it's likely that other programs will also be writing to this directory and you won't get the results that you expect @Nine Wouldn't it be more efficient to change your Sleep to 30000? That way, you aren't repeatedly checking the directory size during the 30 second "delay" period. You wouldn't even need to timer. 😄 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted December 26, 2019 Share Posted December 26, 2019 @Danp2 Well I thought about it, but checking on a large folder with multiple subfolders can take a little while. So I just wanted to make sure it is as close as possible to the 30 secs. “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...
Danp2 Posted December 26, 2019 Share Posted December 26, 2019 Not sure of the OP's requirements, but maybe use $DIR_NORECURSE for the optional flag to prevent recursion of the subdirectories. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Buster2000 Posted December 26, 2019 Author Share Posted December 26, 2019 @Nine this is exactly what I needed and your script works perfectly! Thank you so much for sharing this. I was able to shorten the timer down to 5 seconds because the folder I'm watching is small. @Danp2 this is just an example of the folder I'm using - I just threw the temp folder in there as an example. Danp2 1 Link to comment Share on other sites More sharing options...
junkew Posted December 27, 2019 Share Posted December 27, 2019 Maybe just monitoring events can help improve FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Buster2000 Posted December 27, 2019 Author Share Posted December 27, 2019 @Nine I have one final question. In your script where you say: ; do the things you need to do here How would I add multiple tasks in there, each consecutive task running once the directory stops changing in size? Meaning - once Task 1 is finished due to the folder size not changing anymore. It then runs Task 2, then when the folder stops changing in size, run Task 3 and so on. Thanks! Link to comment Share on other sites More sharing options...
Danp2 Posted December 27, 2019 Share Posted December 27, 2019 @Buster2000 Just stack the calls, like this -- ; Launch task 1 here CheckDirSize("C:\Temp") ; Launch task 2 here CheckDirSize("C:\Temp") ; Launch task 3 here CheckDirSize("C:\Temp") ; etc Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted December 27, 2019 Share Posted December 27, 2019 You mean : CheckDirSize("C:\Temp") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error reading directory") Task1() CheckDirSize("C:\Temp") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error reading directory") Task2() CheckDirSize("C:\Temp") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error reading directory") Task3() ... Or you could make a loop : For $i = 1 to $NUMBER_OF_TASKS CheckDirSize("C:\Temp") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error reading directory") Call ("Task" & $i) Next Buster2000 1 “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...
Buster2000 Posted December 27, 2019 Author Share Posted December 27, 2019 Thanks @Nine that works exactly as expected. Thanks again for your help! 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