Jump to content

How to make the code generic


shiv
 Share

Recommended Posts

Hi AutoIT Help & Support

I need your help to make my code generic

here is the code

Local $sFileList = _FileListToArray($sPath) ; at $sPath i have two files which have the extension .msi and .64msi

$sFileList[1] = "File name1_.msi"        
$sFileList[2] = "File name2_x64.msi"    

In the above two lines of code i do not want to use file names.

i want to use something like

$sFileList[1] = "_.msi"        
$sFileList[2] = "_x64.msi"

But when i use this files name are not recognized at the location of files

is there some way that i can use the extensions to recognize the file


Please Help

Link to comment
Share on other sites

Hi michaelslamet,

1. I have two files 1 with .msi and 2nd with _x64.msi

2. Both the files are placed in some folder, for that i have defined the path in a variable $sPath.

3. Now as i have written in the above code i used

    Local $sFileList = _FileListToArray($sPath)

4. From this line of  code, i am not sure that at which location of array the .msi file will be and at which location the _x64.msi file will be.

i can use

$sFileList[1] = "file name1_.msi"        
$sFileList[2] = "filename2_x64.msi"

but ii would be the hard code as i am mentioning the file names here, i do not want to use the file names in the array location, instead i would prefer to use extension i.e. .msi and _x64 which will work for every new file placed at $sPath.

i hope it may clear to you.

thanks

Link to comment
Share on other sites

I think he means that the filenames might be different but the extentions will remain the same.

This might require some RegExp...

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

_FileListToArray can accept wildcards.

Local $sPath = "filename*.msi"
Would catch both your given examples.

 

-edit

Well, not both.. I didn't see the space.
But a bit of tinkering with the wildcards (they are the same ones DOS or Windows accepts) should be able to catch them.

-edit2

...and I think I misunderstood what you are doing.
It looks like you are trying to change the extension of the file from .64msi to .msi?


 

Edited by tirpider
Link to comment
Share on other sites

You could do 2 calls to _FileListToArray, to find both files.

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

 

Hi Vis,

Why do you need to declare this in your script?

$sFileList[1] = "file name1_.msi"        
$sFileList[2] = "filename2_x64.msi"

As you said, you dont want to hardcode it.

If you need to run it, you can just do something like this:

Run($sFileList[1])

Hi michaelslamet,

We are not sure that which file is located at $sFileList[1] it mat be .msi or .64msi.

Link to comment
Share on other sites

  • Moderators

vis,

This works for me:

#include <Array.au3> ; Only for display
#include <File.au3>

$sPath = @ScriptDir

; List all .msi files
$aList = _FileListToArray($sPath, "*.msi", 1)

; Now look for a matching x64.msi file
For $i = 1 To $aList[0]
    ; Trim the .ext
    $sRoot = StringTrimRight($aList[$i], 4)
    ; And see if there is a matching x64 file
    If FileExists($sPath & "\" & $sRoot & "x64.msi") Then
        ; If so then create array
        Local $aRet[3] = [2, $aList[$i], $sRoot & "x64.msi"]
        ; No point in looking further
        ExitLoop
    EndIf
Next

; Display the result
_ArrayDisplay($aList)
Now you always get the .msi file in element [1] and the x64.msi in element [2]. Good enough? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...