Jump to content

Monitor a folder before moving to next command


Recommended Posts

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

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

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

 

Link to comment
Share on other sites

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. 😄
Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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

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

 

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