Jump to content
Sign in to follow this  
shiv

How to make the code generic

Recommended Posts

shiv

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

Share this post


Link to post
Share on other sites
shiv

Please reply

Share this post


Link to post
Share on other sites
michaelslamet

John, you're such a funny guy :idiot:

Share this post


Link to post
Share on other sites
michaelslamet

Vis,

I think your request is not clear (at least for me). Could you please tell us again what exactly you're trying to accomplish?

Share this post


Link to post
Share on other sites
shiv

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

Share this post


Link to post
Share on other sites
FireFox

Please wait at least 24H before bumping a topic.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
michaelslamet

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])

Share this post


Link to post
Share on other sites
DatMCEyeBall

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

Share this post


Link to post
Share on other sites
tirpider

_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

Share this post


Link to post
Share on other sites
shiv

Hi DatMCEyeBall,

You are right

Share this post


Link to post
Share on other sites
shiv

 

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.

Share this post


Link to post
Share on other sites
Melba23

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 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

 

Share this post


Link to post
Share on other sites
shiv

Thanks to All,

for helping , and thank you very much Melba23, its working. you are really a genius

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  

×