Jump to content

Wait Until File Is Written ... How?


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

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

Link to comment
Share on other sites

  • Moderators

...

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

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

Link to comment
Share on other sites

  • Moderators

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

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

Link to comment
Share on other sites

  • Moderators

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

Link to comment
Share on other sites

  • 2 years later...

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