Sign in to follow this  
Followers 0
ChrisL

How to tell when a directory is stable

5 posts in this topic

I need to monitor a directory to see when it has some files copied in to it, but I need to be sure the file copy has finished.

I tried using dirgetsize() in a loop but this doesn't work.

When the filecopy starts Windows allocates the finished size to the directory. So if its a large file that takes 30 seconds to copy in the directory size is aready showing the final size each check.

Is there an alternative method?

Thanks

Share this post


Link to post
Share on other sites



I donno how to do it in AutoIt,

But Do you know C#?

In C#(.NET generally) you can use a component called System.IO.FileSystemWatcher.

What you can do is write the Waiting function in C#, compile it to an EXE,

and then use RunWait() in your AutoIt code, to run it and wait for it.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

can't u just see if the directory has that file or not.. by _FileListToArray.. just search for file's name in there

Edited by Manjish

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

or easier still.. just see if the "Copying.." window exists or not.. by WinExists


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

Well Thanks for the replies, but the best method I have found so far is to use

Func _FileOpenAPI($sFile)
    Local $GENERIC_READ = 0x80000000, $GENERIC_WRITE = 0x40000000, $OPEN_ALWAYS = 4, $FILE_ATTRIBUTE_NORMAL = 0x00000080, $FILE_SHARE_NONE = 0x00000000, $FILE_SHARE_READ = 0x00000001, $FILE_SHARE_WRITE = 0x00000002
    Local $AFO_h
    $AFO_h = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $sFile, "long", BitOR($GENERIC_READ, $GENERIC_WRITE), "long", $FILE_SHARE_NONE, "ptr", 0, "long", $OPEN_ALWAYS, "long", $FILE_ATTRIBUTE_NORMAL, "long", 0)
    Return $AFO_h[0]
EndFunc  ;==>_FileOpenAPI

Using the "File_Share_None" flag and check each file in the directory to make sure I can open it.

It fails to open if it is mid copy.

Share this post


Link to post
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
Sign in to follow this  
Followers 0