Jump to content
Sign in to follow this  
newroof

Script stops (freeze) -please help

Recommended Posts

newroof

I have this script - works fine for about 50 records and than stops (freeze). If I launch the script again, works for one or two records and then stops again. It doesnt process all records in _FileListToArray. No error messages.

I created the script using AU3Recorder. Can anybody help me - there is any way I can optimize it?

Thanks.

Here is the script:

#include <File.au3>

#Include <Array.au3>

$Folder1 = "C:\working\";

$Folder2 = "c:\complete\"

$Files1 = ""

$Files2 = ""

$File = ""

$FileWin = ""

$Files = _FileListToArray($Folder1)

For $i = 1 To UBound($Files)-2

$Files1 = $Folder1 & $Files[$i]

$Files2 = "c:\complete\" & StringLeft($Files[$i], StringLen($Files[$i]) - 4) & ".jpg"

$File = "c:\templates\" & StringLeft($Files[$i], 9) & ".app"

$FileWin = StringLeft($Files[$i], 9) & ".app"

ShellExecute($File, "Open")

WinWait($FileWin & " - Application","")

If Not WinActive($FileWin & " - Application","") Then WinActivate($FileWin & " - Application","")

WinWaitActive($FileWin & " - Application","")

Send("{CTRLDOWN}{SHIFTDOWN}f{CTRLUP}{SHIFTUP}")

WinWait("All Files (*.*)|*.*||","")

If Not WinActive("All Files (*.*)|*.*||","") Then WinActivate("All Files (*.*)|*.*||","")

WinWaitActive("All Files (*.*)|*.*||","")

Send($Files1)

Send("{ENTER}")

WinWait($FileWin & " - Application","")

If Not WinActive($FileWin & " - Application","") Then WinActivate($FileWin & " - Application","")

WinWaitActive($FileWin & " - Application","")

Send("{CTRLDOWN}{SHIFTDOWN}x{SHIFTUP}{CTRLUP}")

WinWait("Export file","")

If Not WinActive("Export file","") Then WinActivate("Export file","")

WinWaitActive("Export file","")

Send($Files2)

Send("{ENTER}")

WinWait("Export as JPG","")

If Not WinActive("Export as JPG","") Then WinActivate("Export as JPG","")

WinWaitActive("Export as JPG","")

Send("{ENTER}")

WinClose($FileWin & " - Application","")

FileDelete($Files1)

Next

Share this post


Link to post
Share on other sites
Nahuel

Is it me or you posted this twice and also sent an email to the AutoIt email list?

That code is pretty confusing to me, why don't you try to explain what you want to do?

All I can see is that you are using to many WinWait* and Send() functions. A minor typo could be causing you the headache. Try to use some debug methods, like ConsoleWrite or MsgBox(). Place them at the lines you think are not working right. This will help you follow the code's execution and will let you know where exactly it freezes.

Share this post


Link to post
Share on other sites
weaponx

Your coding needs some help. There are multiple concerns here.

1. You don't need to check if a window is active before activating it

2. You didn't have a file only flag on FileListToArray

3. You are assuming all found files have a 3 character extension

4. You have no comments in your code

#include <File.au3>
#Include <Array.au3>
$Folder1 = "C:\working\";
$Folder2 = "c:\complete\"

;Return files only
$Files = _FileListToArray($Folder1, 1)
For $i = 1 To $Files[0]

    ;Append filename to folder
    $Files1 = $Folder1 & $Files[$i]
    
    ;Strip extension from found file, append ".jpg"...this makes the assumption that the existing file isn't a folder and has a 3 character extension
    $tempArray = StringSplit($Files[$i], ".")
    $Files2 = "c:\complete\" & $tempArray[1] & ".jpg"
    
    ;???? Only retrieve left 9 characters from filename
    $File = "c:\templates\" & StringLeft($Files[$i], 9) & ".app"
    $FileWin = StringLeft($Files[$i], 9) & ".app"

    ShellExecute($File, "Open")
    WinWait($FileWin & " - Application", "")
    WinActivate($FileWin & " - Application", "")
    WinWaitActive($FileWin & " - Application", "")
    Send("{CTRLDOWN}{SHIFTDOWN}f{CTRLUP}{SHIFTUP}")
    WinWait("All Files (*.*)|*.*||", "")
    WinActivate("All Files (*.*)|*.*||", "")
    WinWaitActive("All Files (*.*)|*.*||", "")
    Send($Files1)
    Send("{ENTER}")
    WinWait($FileWin & " - Application", "")
    WinActivate($FileWin & " - Application", "")
    WinWaitActive($FileWin & " - Application", "")
    Send("{CTRLDOWN}{SHIFTDOWN}x{SHIFTUP}{CTRLUP}")
    WinWait("Export file", "")
    WinActivate("Export file", "")
    WinWaitActive("Export file", "")
    Send($Files2)
    Send("{ENTER}")
    WinWait("Export as JPG", "")
    WinActivate("Export as JPG", "")
    WinWaitActive("Export as JPG", "")
    Send("{ENTER}")
    WinClose($FileWin & " - Application", "")
    FileDelete($Files1)
Next

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  

×