Sign in to follow this  
Followers 0
LagunaScripter

Newb question: Arrays

2 posts in this topic

Hi everyone,

I'm quite new to AutoIT and I'm struggling with how to solve the following problem:

I'm working on a script that will perform a function on all files matching wildcards submitted on the command line, for example:

"MyScript.exe *.pdf" will action on all PDF files. -So far so good. Here is what I can't get my brain wrapped around:

I want to be able to issue a command linue à là this: "MyScript.exe *.pdf *.doc *.xls *.html" and so forth, but I don't want to be limited to a pre-defined numnber of parameters.

I am pretty sure I know how to identify how many parameters have been passed on the command line, but I'm not (yet) able to DO anything with those mulitple parameters.

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

LagunaScripter,

Command line parameters are put in the special array $CmdLine. The [0] element of this array tells you how many parameters there were and the [1], [2] ..... [n] elements tell you what they were.

In your case ("MyScript.exe *.pdf *.doc *.xls *.html") you would have the following array:

[0] 4

[1] .pdf

[2] .doc

[3] .xls

[4] .html

To access these parameters you use $CmdLine[?] where ? is the index of the element. Perhaps the easiest way (as you say you want to match them) is to use a loop:

For $i = 1 To $CmdLine[0] ; Runs through each parameter in turn
    ; Do what you want with the parameter
    Function($CmdLine[$i])
Next

Please ask if anything is unclear.

M23

Edit: Speeling!

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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