boein

Check if file copy completed

9 posts in this topic

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

 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
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

>Exit code: 0

REAL search results

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

Share this post


Link to post
Share on other sites

I use Yashied's Copy UDF. Lots of options within that. I've used it successfully to copy across our company WAN to locations across the globe.

'?do=embed' frameborder='0' data-embedContent>>


Who lied and told you life would EVER be fair?

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