Sign in to follow this  
Followers 0
ConstantineGeorgantzas

Putting a file list into an array

22 posts in this topic

#1 ·  Posted (edited)

Please refer to http://www.autoitscript.com/forum/index.ph...=50070&st=0 as a means to gain a better understanding on this topic's subject of discussion; it is where this topic's train of thought all started.

Edited by ConstantineGeorgantzas

Share this post


Link to post
Share on other sites



First thing - There is a function built into AutoIT called _FileListToArray

Second - Why did you duplicate your previous topic

http://www.autoitscript.com/forum/index.ph...c=50070&hl=

Third - Why didn't you just take my advice? This is so much faster and more reliable.

Do yourself a favor and get a Professional version of Acrobat 7 or 8. Use the built-in batch processing on the File menu in conjunction with the PDF optimizer.

http://www.adobeforums.com/cgi-bin/webx/.3bc2c522

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Third - Why didn't you just take my advice? This is so much faster and more reliable.

Well I don't think I should take that advice because I have told my boss that I would program and if I were to ask for Adobe Professional it may appear a sign of defeat. Also, my boss has no other work for me to do so if things are done to quickly or by a computer program I may get fired.

Second - Why did you duplicate your previous topic

http://www.autoitscript.com/forum/index.ph...c=50070&hl=

What do you mean?

And Thank you for the function.

Edited by ConstantineGeorgantzas

Share this post


Link to post
Share on other sites

Where is your list...on paper?

I hope your next reply is more useful than your last.

To answer your question: Tthe file list is found in a directory or on a search window.

Share this post


Link to post
Share on other sites

Explain yourself a little better if you want help. Who knows where your file locations are? Have you collected them somewhow? Do you have a list in Notepad? Do you have a list on paper? Lose the tart attitude.


IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

What do you mean?I think he means...we've been trying to help you in your other post - I've got a post there waiting for you now, in fact, there's no need to have two topics about the same thing! Isn't what you're asking here exactly what we're working through in your first post?

Whether you know it or not, that is called double-posting and is considered rude, if you do it on purpose. Kindly refrain from it in the future.


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Can you help me with this?

That's exactly what we're talking about...you just posted the SAME EXACT QUESTION in two topics, both of which are still active and near the top of the list of current topics. If we help here, should we put the same response in both topics in which you've now posed this question? If not, someone else may see the topic we did not help in, and thinking it's unanswered, spend time trying to help you when you've already got the answer in the other topic!

I can't help you with your compression functions because I don't have any Adobe products except Reader.

I am becoming less inclined to help you with your file listing questions as well.

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

Automate compression of PDF's using Acrobat Standard:

-Place all the files to be compressed in the $PDFINPUT folder below the Script Directory

-Files will be output to $PDFOUTPUT

-Change $ACROBAT, $REDUCE, $SAVEAS variables to match Acrobat 6 window names

#include <File.au3>
#include <Array.au3>

;Match exact window titles
Opt("WinTitleMatchMode", 3)

$ACROBAT = "Adobe Acrobat Standard"
$REDUCE = "Reduce File Size"
$SAVEAS = "Save As"

$PDFINPUT = "IN"
$PDFOUTPUT = "OUT"

$PDFLIST = _FileListToArray ( @ScriptDir & "\" & $PDFINPUT, "*.pdf",1 )

$RESULT = FileDelete(@ScriptDir & "\" & $PDFOUTPUT & "\*.pdf")
If $RESULT = 0 Then
    MsgBox(0,"","Output folder not empty")
    ;Exit
EndIf

;For $X = 1 to 1
For $X = 1 to $PDFLIST[0]
    ;Force new instance of Acrobat - CAREFUL
    ;Run(@ProgramFilesDir & "\Adobe\Acrobat 7.0\Acrobat\acrobat.exe /n " & @ScriptDir & "\" & $PDFINPUT & "\" & $PDFLIST[$X])
    
    ;Open file in Acrobat 7
    Run(@ProgramFilesDir & "\Adobe\Acrobat 7.0\Acrobat\acrobat.exe " & @ScriptDir & "\" & $PDFINPUT & "\" & $PDFLIST[$X])
    WinActivate (StringFormat("%s - [%s]",$ACROBAT,$PDFLIST[$X]))
    WinWaitActive (StringFormat("%s - [%s]",$ACROBAT,$PDFLIST[$X]))

    ;This line doesn't work since, I don't think Acrobat uses standard controls for menus
    ;WinMenuSelectItem("Adobe Acrobat Standard", "", "&File", "Reduce File Si&ze..." )
    
    ;Send Alt-F to open file menu
    Send ( "!f" )
    ;Send z to open Reduce File Size
    Send ( "z" )
    
    WinActivate ($REDUCE)
    WinWaitActive ($REDUCE)
    
    ;Click OK Button, leaving Acrobat 7 as default output
    ControlClick ($REDUCE, "","[CLASS:Button; INSTANCE:2]" )
    
    WinActivate ($SAVEAS)
    WinWaitActive ($SAVEAS)
    ;Set file path to output folder with same filename
    ControlSetText($SAVEAS, "", "[CLASS:Edit; INSTANCE:1]" , @ScriptDir & "\" & $PDFOUTPUT & "\" & $PDFLIST[$X] )
    ;Click save
    ControlClick ($SAVEAS, "","[CLASS:Button; INSTANCE:2]" )
    
    ;Reactivate main window
    WinActivate (StringFormat("%s - [%s]",$ACROBAT,$PDFLIST[$X]))
    WinWaitActive (StringFormat("%s - [%s]",$ACROBAT,$PDFLIST[$X]))
    ;Send CTRL-W to close file
    Send ( "^w" )
    WinWaitActive ($ACROBAT)
Next

;_ArrayDisplay($PDFLIST)

Share this post


Link to post
Share on other sites

What do you mean?

I think he means...we've been trying to help you in your other post - I've got a post there waiting for you now, in fact, there's no need to have two topics about the same thing! Isn't what you're asking here exactly what we're working through in your first post?

Whether you know it or not, that is called double-posting and is considered rude, if you do it on purpose. Kindly refrain from it in the future.

Sorry, I am new to forums and I had not thought through my actions. Also, as I have previously stated, the script has various parts, which I am trying to bring together, so when I am looking to connect them I bring up the same things in different topics. I am just eager to finish; that is all.

I have also deleted duplicates.

Sorry

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Sorry, I am new to forums and I had not thought through my actions. Also, as I have previously stated, the script has various parts, which I am trying to bring together, so when I am looking to connect them I bring up the same things in different topics. I am just eager to finish; that is all.

I have also deleted duplicates.

Sorry

No prob. :)

Didn't mean to be harsh - I just saw you do the same thing two times in a row, which is a common pattern of people who don't respect ettiquite and are generally considered as being 'beyond help' (the whole, 'I want what I want, and NOW' attitude doesn't go over well when we're all just trying to help out of the goodness of our hearts). Glad that wasn't the case here.

Thanks for understanding :P

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thank you WeaponX, but I think you have done too much.

I still need time to understand exactly what is there and activate it: I cannot get it to work yet (I get a message that says output folder not empty).

I'll get back to you when I understand more.

Edited by ConstantineGeorgantzas

Share this post


Link to post
Share on other sites

Here are my questions and comments about WeaponX's program:

1) I don't understand

$PDFINPUT = "IN"

$PDFOUTPUT = "OUT"

and their use throughout the program.

2) The FileDelete function looks like a very nice way to filter a search. Does your program use that approach?

3) What do these things mean?: [CLASS:Button; INSTANCE:2], [CLASS:Edit; INSTANCE:1].

Did you use the AutoItInfo program to get the info?

4) "For $X = 1 to $PDFLIST[0]" seems like an infinite loop if you use statements like "WinActivate (StringFormat("%s - [%s]",$ACROBAT,$PDFLIST[$X]))"

5) The StringFormat function really confuses me; can you explain it more clearly than the help menu?

6) I can't get the _ArrayDisplay fucntion to display the array.

7) I use Adobe 6.0 so I will use "Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & @ScriptDir & "\" & $PDFINPUT & "\" & $PDFLIST[$X])" as opposed to "Run(@ProgramFilesDir & "\Adobe\Acrobat 7.0\Acrobat\acrobat.exe " & @ScriptDir & "\" & $PDFINPUT & "\" & $PDFLIST[$X])"

Share this post


Link to post
Share on other sites

When I run your script this is the error message I get:

C:\Documents and Settings\CGeorgantzas\Desktop\Autoit Exercises\WeaponX's Code2.au3 (83) : ==> Subscript used with non-Array variable.:

For $X = 1 to $PDFLIST[0]

For $X = 1 to $PDFLIST^ ERROR

>Exit code: 1 Time: 43.293

By the way, I had to add the function called _FileListToArrayEx that james3mg gave me; #include <FileListToArrayEX.au3> just didn't work.

Yeah, good job though. It prompts like you say. Just a few more kinks need to be worked out, at least on my computer.

Share this post


Link to post
Share on other sites

When I run your script this is the error message I get:

By the way, I had to add the function called _FileListToArrayEx that james3mg gave me; #include <FileListToArrayEX.au3> just didn't work.

Yeah, good job though. It prompts like you say. Just a few more kinks need to be worked out, at least on my computer.

For the #include to work that way FileListToArrayEX.au3 has to be in the AutoIt3\include folder

If it's in the same folder as the script use

#include "FileListToArrayEX.au3"

Try changing the line For $X = 1 to $PDFLIST[0]

To $X = 1 to Ubound($PDFLIST)-1

That's line 83 according to the error


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

For the #include to work that way FileListToArrayEX.au3 has to be in the AutoIt3\include folder

If it's in the same folder as the script use

#include "FileListToArrayEX.au3"

Try changing the line For $X = 1 to $PDFLIST[0]

To $X = 1 to Ubound($PDFLIST)-1

That's line 83 according to the error

$PDFLIST[0] is the same as Ubound($PDFLIST)-1 here, if $PDFLIST[0] is blank its because his file list isn;t being returned correctly.

Share this post


Link to post
Share on other sites

For the #include to work that way FileListToArrayEX.au3 has to be in the AutoIt3\include folder

If it's in the same folder as the script use

#include "FileListToArrayEX.au3"

Try changing the line For $X = 1 to $PDFLIST[0]

To $X = 1 to Ubound($PDFLIST)-1

That's line 83 according to the error

I thought $PDFLIST[0] and Ubound($PDFLIST)-1 were equivalent.

Share this post


Link to post
Share on other sites

$PDFLIST[0] is the same as Ubound($PDFLIST)-1 here, if $PDFLIST[0] is blank its because his file list isn;t being returned correctly.

Even though Ubound($PDFLIST)-1 and $PDFLIST[0] should be equivalent, when I use $PDFLIST[0] the scripts returns an error message and when I use Ubound($PDFLIST)-1 the script runs. However, the script runs and runs and doesn't do anything else but prompt twice. And then all of a sudden the script stops executing.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Even though Ubound($PDFLIST)-1 and $PDFLIST[0] should be equivalent, when I use $PDFLIST[0] the scripts returns an error message and when I use Ubound($PDFLIST)-1 the script runs. However, the script runs and runs and doesn't do anything else but prompt twice. And then all of a sudden the script stops executing.

The reason $PDFLIST[0] is because the FileListToArrayEx function is failing and $PDFLIST is NOT AN ARRAY if it fails. Ubound is redundandt if the FileListToArrayEx is successful.

Did you make sure this was in your script:

#include <FileListToArrayEX.au3>

and the file FileListToArrayEX.au3 should contain:

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        Local $iPid
        If Not $iRecurse Then
            $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC] & '" /b /o-e /od', '', @SW_HIDE, 6)
        Else
            $iPid = Run(@Comspec & ' /c dir /b /s /a "' & $sPath & '\' & $aSplit[$iCC] & '"', '', @SW_HIDE, 6)
        EndIf
        While 1
            $sRead &= StdoutRead($iPid)
            If @error Then ExitLoop
        WEnd
    Next
    If StringStripWS($sRead, 8) = '' Then Return SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft(StringTrimLeft($aFSplit[$iCC], StringInStr($aFSplit[$iCC], '\', 0, -1)), _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 1
                If StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 2
                If Not StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc
Edited by weaponx

Share this post


Link to post
Share on other sites

Using #include <FileListToArrayEX.au3> gives me an error. Instead I just include the function _FileListToArrayEx at the top of the script.

Also, can you re-write: "The reason $PDFLIST[0] is because the FileListToArrayEx function is failing and $PDFLIST is NOT AN ARRAY if it fails. Ubound is redundandt if the FileListToArrayEx is successful."

I am not sure what you mean.

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