Jump to content

Recommended Posts

Posted

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.  

Posted

Have a look at : FileFlush

Your script would also be helpful for further support ;).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

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}")
 

 

Posted

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

 

Posted

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

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

Posted

@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!

Posted

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

 

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
  • Recently Browsing   0 members

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