pranaynanda Posted March 31, 2016 Share Posted March 31, 2016 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 More sharing options...
AutoBert Posted March 31, 2016 Share Posted March 31, 2016 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 More sharing options...
JohnOne Posted March 31, 2016 Share Posted March 31, 2016 $fmsi = FileFindFirstFile("*.msi") $fexe = FileFindFirstFile("*.exe") Do everything twice. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
rudi Posted March 31, 2016 Share Posted March 31, 2016 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 More sharing options...
Danyfirex Posted March 31, 2016 Share Posted March 31, 2016 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 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
pranaynanda Posted March 31, 2016 Author Share Posted March 31, 2016 2 hours ago, JohnOne said: $fmsi = FileFindFirstFile("*.msi") $fexe = FileFindFirstFile("*.exe") Do everything twice. @JohnOne If you remove the comments, you'll see that i was doing what you say. The problem is that I seen gaps in the listview which i cannot understand. Link to comment Share on other sites More sharing options...
AutoBert Posted March 31, 2016 Share Posted March 31, 2016 54 minutes ago, pranaynanda said: @JohnOne If you remove the comments, you'll see that i was doing what you say. I suggest he means 2 loops, but the solution Danyfirex posted is the smallest and runable. Link to comment Share on other sites More sharing options...
Danyfirex Posted March 31, 2016 Share Posted March 31, 2016 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 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now