Jump to content

Check if file copy completed


boein
 Share

Recommended Posts

Hi,

When you want to copy a file to a network share sometimes it takes 1 sec sometimes 3 sec before it's copied.  How can you check if the file is completely copied before continuing with your script.

One remark, the copy is not initiated by an autoit command but with "file save-as" executed by autoit using the controlsend command.  Meaning you really have to wait before the program has finished the "save" before the script can continue.  I tried to check filexists in a loop or filesize but it doesn't seem to work.  It's also impossible to read the statusbar of the file-save completing because I cannot retreive the controlID of that statusbar.  The application is Lotus Notes 7 and it almost reveals no control id's.  Anyone ideas?

Regards,

Boein

 

Link to comment
Share on other sites

Another approach would be to not automate the GUI but to use COM.

When calling the SaveAs method you can be sure that your script only continues when the file has been written. Plus you can check for errors..

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Another approach would be to not automate the GUI but to use COM.

When calling the SaveAs method you can be sure that your script only continues when the file has been written. Plus you can check for errors..

Hi,

I was using autoit for this reason :-).  I cannot approach lotus notes using COM without installing additional sofware I guess, and I haven't played witth notes APi's before.  Using Autoit would be the easiest way in this case, but unfortunately you're less in control for this matter.  Anyway is there no way to check if i file is saved using autoit instead of COM, checking "file in use" in a loop or something like that?

Regards,

Boein

Link to comment
Share on other sites

_WinAPI_FileInUse()

Thanks,

but this one also does not seem to wait long enough

Imagine this:Lotus Notes client is open then - file - save attachment

$clipfile = "h:somepdf.pdf"

send("!s")

while  fileexists($clipfile) = 0

wend

while _WinAPI_FileInUse ($clipfile) = 1

       sleep(1000)

wend

msgbox ($mb_systemmodal,"",$clipfile)

When executing this script, on the notes client, in the status bar I can see

saving somepdf.pdf10%

saving somepdf.pdf 50%

saving somepdf.pdf 90%

saving somepdf.pdf100%

but before reaching 100% I already got the msgbox from autoit displayed, meaning autoit doesn's wait before the file save is completed.

Regards,

Boein

 

 

regards,

Boein

Link to comment
Share on other sites

Or use _WinAPI_LockFile to get exclusive access to the file. If successful the file has been fully written. Don't forget to release the file again.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

 

$clipfile = "h:somepdf.pdf"

send("!s")

sleep(1000)

while  fileexists($clipfile) = 0

wend

while _WinAPI_FileInUse ($clipfile) = 1

       sleep(1000)

wend

msgbox ($mb_systemmodal,"",$clipfile)

 

Hi all,

Maybe the _WinAPI_FileInUse was working after all.  I put a sleep of 1sec between the "save" and start of _WinAPI_FileInUse check and that seems to work.  Even a file that takes >5 secs to save seems to wait.  I guess you need to put a tiny break between issuing the "save" and the first check to see if the file is in use, otherwise autoit is too fast and already did the fileinuse check before the save was started?  But strange thing is that the fileexists routine did not prevent to wait until the file was created.

Anyway sleeping 1sec is acceptable for me :-)

Reagards

Boein

Link to comment
Share on other sites

instead of just checking to see if the file exists, tell the script to wait until the file exists.

$clipfile = "h:\somepdf.pdf"
send("!s")

do
sleep(100)
until fileexists($clipfile)

 
while _WinAPI_FileInUse ($clipfile) = 1
       sleep(1000)
wend
msgbox ($mb_systemmodal,"",$clipfile)
If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

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