Sign in to follow this  
Followers 0
mozart90

Wait Until File Is Written ... How?

16 posts in this topic

#1 ·  Posted (edited)

Hi

I've got a problem. In my skript I have to wait until a file saving is finished so I can proceed loading the file in another application.

The question is how can I find out when the file is written completly to disk.

I 've tried it with the fileopen command, but I didn't get an error ...

while 1
$file  = fileopen("c:\testfile.bmp",1)
if @error then 
continue loop
else 
exit loop 
wend

msgbox(0,"","Filewriting  has finished")

Any suggestions?

Geetings Mozart90

Edited by mozart90

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi

I've got a problem. In my skript I have to wait until a file saving is finished so I can proceed loading the file in another application.

The question is how can I find out when the file is written completly to disk.

I 've tried it with the fileopen command, but I didn't get an error ...

while 1
$file  = fileopen("c:\testfile.bmp",1)
if @error then 
continue loop
else 
exit loop 
wend

msgbox(0,"","Filewriting  has finished")

Any suggestions?

Geetings Mozart90

How is the file being written to disk, is it from the AutoIT script or another application? Edited by billmez

Share this post


Link to post
Share on other sites

This might work, but it depends on how the file is being written.

While 1
    $a_size = FileGetSize("c:\testfile.bmp")
    If $a_size == 0 Then
        Sleep(200)
        ContinueLoop
    Else
        Sleep(200)
        $b_size = FileGetSize("c:\testfile.bmp")
        If $a_size == $b_size Then ExitLoop
    EndIf
WEnd
MsgBox(0, "", "File has finished installing.")

Share this post


Link to post
Share on other sites

...

the file is written from adobe acrobat. it is an jpg export from a hole page, which I want to crop with another proggi. (Starts with cmd line option jpg name). The saving in Acrobat time is very different, it depend on the amount of grafics on the page thats why i can't use a simple sleep().

the idea comparing the filesize I didn' tried yet because it failed with the Internet explorer....

Greetings Mozart90

Share this post


Link to post
Share on other sites

...

the file is written from adobe acrobat. it is an jpg export from a hole page, which I want to crop with another proggi. (Starts with cmd line option jpg name). The saving in Acrobat time is very different, it depend on the amount of grafics on the page thats why i can't use a simple sleep().

the idea comparing the filesize I didn' tried yet because it failed with the Internet explorer....

Greetings Mozart90

Are you using AutoIT to save the file from Acrobat, or doing it manually?

Share this post


Link to post
Share on other sites

...

the file is written from adobe acrobat. it is an jpg export from a hole page, which I want to crop with another proggi. (Starts with cmd line option jpg name). The saving in Acrobat time is very different, it depend on the amount of grafics on the page thats why i can't use a simple sleep().

the idea comparing the filesize I didn' tried yet because it failed with the Internet explorer....

Greetings Mozart90

Does Adobe not give you some kind of progress indicator while it is exporting?

Share this post


Link to post
Share on other sites

Does Adobe not give you some kind of progress indicator while it is exporting?

belive it or not this time it works (comparing the filesize)

and yes there is a progress bar in the status line at the bottom fo the window...

Is ther the possibility to 'read' this progress bar.

@billmez

I use some send() commands

Mozart90

Share this post


Link to post
Share on other sites

belive it or not this time it works (comparing the filesize)

and yes there is a progress bar in the status line at the bottom fo the window...

Is ther the possibility to 'read' this progress bar.

@billmez

I use some send() commands

Mozart90

If that works, stay with it. Otherwise, is there another command you can send to Acrobat after the send commands you are currently using that will not complete until the file is saved (like file-close). If so, you can insert that in your command chain and then do your file processing after it.

Share this post


Link to post
Share on other sites

belive it or not this time it works (comparing the filesize)

and yes there is a progress bar in the status line at the bottom fo the window...

Is ther the possibility to 'read' this progress bar.

@billmez

I use some send() commands

Mozart90

If you can get the controlID you may be able to use ControlCommand( "title", "text", controlID,"IsVisible", "").

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

From help FileOpen:

Success: Returns a file "handle" or use with subsequent file functions.

Failure: Returns -1 if error occurs.

-1 is not 0 so it's true.. Might want to look at that. I'm not sure.

Else use this: FileExists

Edited by Manadar

Share this post


Link to post
Share on other sites

From help FileOpen:

Success: Returns a file "handle" or use with subsequent file functions.

Failure: Returns -1 if error occurs.

-1 is not 0 so it's true.. Might want to look at that. I'm not sure.

Else use this: FileExists

He is not opening a file through AutoIT, it is being opened and saved through Adobe Acrobat. FileExists will return true as long as the file is there, even if it is still open and being written to. That is his original problem, finding when the file is completed.

Share this post


Link to post
Share on other sites

belive it or not this time it works (comparing the filesize)

and yes there is a progress bar in the status line at the bottom fo the window...

Is ther the possibility to 'read' this progress bar.

@billmez

I use some send() commands

Mozart90

i'd say to watch the progress bar, check out PixelGetColor() or PixelChecksum() either could easily be used to tell when the progress bar has completed.


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i'd say to watch the progress bar, check out PixelGetColor() or PixelChecksum() either could easily be used to tell when the progress bar has completed.

My idea, sometimes the title changes or a window closes. In that case it is Really easy.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Like I said, you can use ControlCommand(). This works on Adobe Standard 6.0:

While 1
$IsVisible = ControlCommand("Adobe Acrobat Standard", "", "AVL_AVView13", "IsVisible", "")
If $IsVisible == 1 Then MsgBox(0, "", "IS Visible!!!", 1)
If $IsVisible == 0 Then MsgBox(0, "", "NOT Visible!!!", 1)
Sleep(1000)
WEnd
Edited by big_daddy

Share this post


Link to post
Share on other sites

the quick and easy way:

Dim $i1=1, $i2=2
While $i1 <> $i2 or $i1 = 0
$i1 = FileGetSize($FileName)
Sleep(5000)
$i1 = FileGetSize($FileName)
Wend

Basically, if the file stops growing, then you can assume it's done. Not as elegant as watching for a known progress bar, but it is easier to re-use.

Share this post


Link to post
Share on other sites

Has anyone tried to use _WinAPI_WaitForSingleObject() UDF to accomplish waiting for a file to complete writing (without busy waiting, i.e. polling with sleep() )? Thanks. Umesh

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