Jump to content

Find all exe and msi in folder


Recommended Posts

How do I make this work?

Func _Populate()
   ;Dim $f[1]
    $f = (FileFindFirstFile("*.msi")) Or (FileFindFirstFile("*.exe"))
    ;$g=FileFindFirstFile("*.exe")

    Dim $array[1]
    $i = 0
    Do
        $s = FileFindNextFile($f)
        ;$t= FileFindNextFile($g)
        If Not @error Then
            $array[$i] = $s
            $i += 1
    ;       array[$i] = $t
     ;       $i += 1
            ReDim $array[$i + 1]
         EndIf
         #cs If Not @error Then
            $array[$i] = $t
            $i += 1
            ReDim $array[$i + 1]
        EndIf
        #ce
    Until @error
    ReDim $array[$i]

I want to find all exe and msi in a folder. I just can't get the Or function to work properly. Please help

Link to comment
Share on other sites

You cant combine 2 FindFileFirstFile in one line, as FileFindFindNextFile needs a handle but which of both should be used. It's only possible to do once for *.msi loop with thatb handle until FileFindNextFile throws error and the the same procedure for  *.exe.

Using _FileListToArrayRec allows to set multiple filters.

Link to comment
Share on other sites

Hi.

 

FileFindFirstFile() *GIVES* you a handle. So if you need to catch more than one file type, IMHO the best approach is to search through *ALL* files in a folder and to selecively grab those file types, you are looking for.

 

#include <array.au3>

$Folder = "C:\install\"
$h = FileFindFirstFile($Folder & "*.*")
If $h = -1 Then
    MsgBox(0, "Error", "No files found in " & $Folder)
    Exit
EndIf

$RegExMSIorEXE = "(?i)(.*?\.msi$|.*?\.exe$)" ; any string ending with ".msi" or ".exe"
$ResultStr = ""

While 1
    $next = FileFindNextFile($h)
    If @error Then ExitLoop
    If @extended Then ContinueLoop ; skipp directories even when they match the naming scheme *.exe / *.msi
    If StringRegExp($next, $RegExMSIorEXE) Then $ResultStr &= $next & "|"
WEnd

If $ResultStr = "" Then
    MsgBox(0, "Searching MSI or EXE", "No MSI or EXE files found in Folder """ & $Folder & """")
Else
    $ResultStr = StringTrimRight($ResultStr, 1) ; cut off final "|"
    $aResult = StringSplit($ResultStr, "|")
    _ArrayDisplay($aResult)
EndIf

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Or simply this.

 

#include <Array.au3> ; Only required to display the arrays
#include <File.au3>


Local $aArray = _FileListToArrayRec(@SystemDir& "\", "*.msi;*.exe", $FLTAR_FILES, $FLTAR_NORECUR)
_ArrayDisplay($aArray)

Saludos

Link to comment
Share on other sites

Using the way you ask for...

#include <MsgBoxConstants.au3>
#include <array.au3>
Example()

Func Example()
    ; Assign a Local variable the search handle of all files in the current directory.
    Local $hSearch1 = FileFindFirstFile(@ScriptDir & "\test\" & "*.msi")
    Local $hSearch2 = FileFindFirstFile(@ScriptDir & "\test\" & "*.exe")
    Local $aFiles[0]

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch1 = -1 Or $hSearch2 = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
        Return False
    EndIf

    ; Assign a Local variable the empty string which will contain the files names found.
    Local $sFileName = ""
    Local $iError1 = -1
    Local $iError2 = -1

    While 1
        $sFileName = FileFindNextFile($hSearch1)
        $iError1 = @error
        If Not $iError1 Then _ArrayAdd($aFiles, $sFileName)
        $sFileName = FileFindNextFile($hSearch2)
        $iError2 = @error
        If Not $iError2 Then _ArrayAdd($aFiles, $sFileName)
        If $iError1 And $iError2 Then ExitLoop
    WEnd
    _ArrayDisplay($aFiles)
    ; Close the search handle.
    FileClose($hSearch1)
    FileClose($hSearch2)
EndFunc   ;==>Example

Saludos

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