Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Wait til File is Saved to continue Script


  • Please log in to reply
5 replies to this topic
CuzzinChizzy
  • Members
  • 10 posts
  • Last active: Nov 05 2014 06:02 PM
  • Joined: 28 Oct 2014

I have a loop in a script that I'm working on, where I want to wait until a file is done being saved (basically til the save progress bar is completely full and this box dissapears) before moving on to the next step, which is showing a Msgbox.  But for some reason, the Msgbox keeps showing up instantly and blocking the save progress bar.

 

 

I tried using this code

Loop
{
    FileMove, X:\CEDR\Sound\HydraReels\Flash\%OutputVar%, X:\CEDR\Sound\HydraReels\Flash\%OutputVar%, 1 ; renames the file to the same file name
    If ErrorLevel     ; if ErrorLevel = 0 the file write is complete
     break
}

 

Msgbox, 1, Done?,press "Enter" or`rclick "OK" to continue.
KeyWait, Enter, D

 

 

I read somewhere on the forums that this code is supposed to try to rename the file(which shouldn't be possible if it's still saving), and continue the loop trying until it can.

Why is the next step in my script (the Msgbox), happening  before it has finished?  Am I missing something?

;This is a script to help speed up the Flash conversion process
;All wav files should be loaded into the Adobe Flash library before running it



;Save Flash Document and enter Game Name

^!q::
InputBox, OutputVar, Sound Assets, `r		       Enter Game Name:`r`r		        (ie. JackpotParty)`r`r"SoundAssets" will automatically be added to title
;KeyWait, Enter, D
FileCreateDir, X:\CEDR\Sound\HydraReels\Flash\%OutputVar%
Sleep, 300
Run, "X:\CEDR\Sound\HydraReels\Flash\%OutputVar%" 
Sleep, 1000
SendInput {Alt down}
Sleep, 100
SendInput {TAB}
Sleep, 100
SendInput {Alt up}
Sleep, 300
SendInput ^+s
Sleep, 500
SendInput %OutputVar%SoundAssets
Sleep, 300
SendInput !d
Sleep, 100
SendInput X:\CEDR\Sound\HydraReels\Flash\%OutputVar% {Enter}
Sleep, 500
SendInput !s


Loop 
{
    FileMove, X:\CEDR\Sound\HydraReels\Flash\%OutputVar%, X:\CEDR\Sound\HydraReels\Flash\%OutputVar%, 1 ; renames the file to the same file name
    If ErrorLevel ; if ErrorLevel = 0 the file write is complete
     break
}



Msgbox, 1, Done?,press "Enter" or`rclick "OK" to continue.
KeyWait, Enter, D



;Rename Library

SendInput ^m
Sleep, 300
SendInput NEWrenameLibrary.jsfl !d
SendInput C:\Users\cpieper\Desktop\My Files\Misc {Enter}
Sleep, 300
;KeyWait, Enter, D
SendInput !o
SendInput {Enter}
Sleep, 300




;Create Sound Objects from Library

SendInput ^m
Sleep, 300
SendInput createSoundObjects.jsfl {Enter}
;KeyWait, Enter, D
Sleep, 300




;Copy Code from Flash's output tab

MouseMove,1424,889,0
MouseClick
SendInput ^c




;Create a new Class, Name, and paste code into Flash Script and save

MouseMove,1521,51
MouseClick
MouseMove,1864,271
MouseClick
SendInput %OutputVar%SoundAssets
Sleep, 300 
;KeyWait, Enter, D
SendInput {Enter}
SendInput {Down}{Down}{Down}{Tab}import flash.media.Sound;{Down}{Down}{Down}{Down}^v ^+s
Sleep, 500
;KeyWait, Enter, D
SendInput {Enter}



;Publish the SWF

SendInput !w 1
Sleep, 100
SendInput ^+{F12} 
Sleep, 300
SendInput !f %OutputVar%SoundAssets
Sleep, 300
SendInput !p
Msgbox, 1, Publish SWF,Was SWF successfully created?`rThen click "OK" or press "Enter"
;KeyWait, Esc, D
SendInput {Esc}




;Generate Flash sound code and save to Notepad doc

SendInput ^m
Sleep, 300
SendInput FlashSoundCode.jsfl
Sleep, 300
SendInput !d
Sleep, 100
SendInput C:\Users\cpieper\Desktop\My Files\Misc {Enter}                       
SendInput !o
SendInput {Enter}
Sleep, 300
MouseMove,1424,889,0
MouseClick
SendInput ^c                                               
Run, Notepad.exe
Sleep, 500
SendInput ^v
Sleep, 300
SendInput ^s
Sleep, 300
SendInput %OutputVar%SoundAssets
Sleep, 300
SendInput !d
Sleep, 300                                              
SendInput X:\CEDR\Sound\HydraReels\Flash\%OutputVar% {Enter}                                    
Sleep, 300
SendInput !s
Sleep, 300
SendInput !{F4}
Sleep, 300





;Generate Unity sound code and save to Notepad doc

SendInput ^m
Sleep, 300
SendInput UnitySoundCode.jsfl
Sleep, 300
SendInput !d
Sleep, 100
SendInput C:\Users\cpieper\Desktop\My Files\Misc {Enter}                       
SendInput !o
SendInput {Enter}
Sleep, 300
MouseMove,1424,889,0
MouseClick
SendInput ^c                                               
Run, Notepad.exe
Sleep, 500
SendInput ^v
Sleep, 300
SendInput ^s
Sleep, 300
SendInput %OutputVar%UnitySoundAssets
Sleep, 300
SendInput !d
Sleep, 300                                             
SendInput X:\CEDR\Sound\HydraReels\Flash\%OutputVar% {Enter}                                    
Sleep, 300
SendInput !s
Sleep, 300
SendInput !{F4}
Sleep, 300



;Save Flash document
SendInput ^s




;Close Flash and Delete unused Action Script file


Msgbox, 1, YOU'RE FINISHED!!!!!, After the Flash Doc is done saving`rClick "OK" or press "Enter"
SendInput !{F4}
FileDelete, X:\CEDR\Sound\HydraReels\Flash\%OutputVar%\%OutputVar%SoundAssets.as
return


gkimz
  • Members
  • 22 posts
  • Last active: Mar 24 2015 02:13 AM
  • Joined: 17 Aug 2014

I think you need to change it to

 

if ! errorlevel

 

 



CuzzinChizzy
  • Members
  • 10 posts
  • Last active: Nov 05 2014 06:02 PM
  • Joined: 28 Oct 2014

Hmmm, I tried adding in the exclamation point and it made no difference. Does the exact same thing.



gkimz
  • Members
  • 22 posts
  • Last active: Mar 24 2015 02:13 AM
  • Joined: 17 Aug 2014

Just read the page on filemove and it said

 

ErrorLevel is set to the number of files that could not be moved due to an error, or 0 otherwise. However, if the source file is a single file (no wildcards) and it does not exist, ErrorLevel is set to 0. To detect this condition, use IfExist or FileExist() on the source file prior to moving it.

Unlike FileCopy, moving a file onto itself is always considered successful, even if the overwrite mode is not in effect.

 

 

 

try it with filecopy and see if that changes anything



CuzzinChizzy
  • Members
  • 10 posts
  • Last active: Nov 05 2014 06:02 PM
  • Joined: 28 Oct 2014

No dice, loop isn't working. Not sure where to go from here.   It's like the loop always breaks right away and the Msgbox that's supposed to wait for the save to be finished pops up.



CuzzinChizzy
  • Members
  • 10 posts
  • Last active: Nov 05 2014 06:02 PM
  • Joined: 28 Oct 2014

Ok, I just figured something out that will work for what I'm trying to do.

 

;Make sure Flash Document was saved successfully
 
WinWait, Saving
WinWaitClose
 
 
This way I don't have to use the loop, I literally just have ahk wait til the saving progress bar finishes and that window closes, to move on to the next step. It's working great. Thanks for your help!