Jump to content

How to tell when a directory is stable


ChrisL
 Share

Recommended Posts

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

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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.

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