Festplatte nach Dateitype durchsuchen

  • Hallo,
    Ich würde gerne alle .exe Dateien von einer Festplatte auflisten und wenn möglich in eine .txt Datei schreiben.
    Beim suchen sollen ebenfalls die Unterverzeichnisse nach .exe Dateien durchsucht werden.

    Gibt es dafür schon eine Funktion , UDF oder ähnliches ?

    Hochachtungsvoll
    derBrot

  • Ja.

    Spoiler anzeigen
    [autoit]


    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

    [/autoit] [autoit][/autoit] [autoit]

    ; #INDEX# =======================================================================================================================
    ; Title .........: _RecFileListToArray
    ; AutoIt Version : v3.3.1.1 or higher
    ; Language ......: English
    ; Description ...: Lists files and\or folders in a specified path with optional recursion and sort.
    ; Remarks .......:
    ; Note ..........:
    ; Author(s) .....: Melba23
    ; Remark ........: Modified Array.au3 functions - credit: Jos van der Zande, LazyCoder, Tylo, Ultima, SolidSnake and gcriaco
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #CURRENT# =====================================================================================================================
    ; _RecFileListToArray: Lists files and\or folders in a specified path with optional recursion and sort.
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; _RFLTA_AddFileLists ....; Add element to list which is resized if necessary
    ; _RFLTA_AddToList .......; Add internal arrays after resizing and optional sorting
    ; _RFLTA_ArraySearch .....; Search array for partial match
    ; _RFLTA_ArraySort .......; Wrapper for QuickSort function
    ; _RFLTA_QuickSort .......: recursive array sort
    ; _RFLTA_ArrayConcatenate : Join 2 arrays
    ; _RFLTA_ArrayInsert .....: Insert element into array
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _RecFileListToArray
    ; Description ...: Lists files and\or folders in a specified path with optional recursion and sort. Compatible with existing _FileListToArray syntax
    ; Syntax.........: _RecFileListToArray($sPath[, $sInclude_List = "*"[, $iReturn = 0[, $fRecur = 0[, $fSort = 0[, $sReturnPath = 1[, $sExclude_List = ""]]]]]])
    ; Parameters ....: $sPath - Initial path used to generate filelist. If path ends in \ then folders will be returned with an ending \
    ; $sInclude_List - Optional: the filter for included results (default is "*"). Multiple filters must be separated by ";"
    ; $iReturn - Optional: specifies whether to return files, folders or both
    ; |$iReturn = 0 (Default) Return both files and folders
    ; |$iReturn = 1 Return files only
    ; |$iReturn = 2 Return folders only
    ; $fRecur - Optional: specifies whether to Search recursively in subfolders
    ; |$fRecur = 0 (Default) Do not Search in subfolders
    ; |$fRecur = 1 Search in subfolders
    ; $fSort - Optional: sort ordered in alphabetical and depth order
    ; |$fSort = 0 (Default) Not sorted
    ; |$fSort = 1 Sorted
    ; $sReturnPath - Optional: specifies displayed path of results
    ; |$sReturnPath = 0 File/folder name only
    ; |$sReturnPath = 1 (Default) Initial path not included
    ; |$sReturnPath = 2 Initial path included
    ; $sExclude_List - Optional: the filter for excluded results (default is ""). Multiple filters must be separated by ";"
    ; Requirement(s).: v3.3.1.1 or higher
    ; Return values .: Success: One-dimensional array made up as follows:
    ; |$array[0] = Number of Files\Folders returned
    ; |$array[1] = 1st File\Folder
    ; |$array[2] = 2nd File\Folder
    ; |...
    ; |$array[n] = nth File\Folder
    ; Failure: Null string and @error = 1 with @extended set as follows:
    ; |1 = Path not found or invalid
    ; |2 = Invalid $sInclude_List
    ; |3 = Invalid $iReturn
    ; |4 = Invalid $fRecur
    ; |5 = Invalid $fSort
    ; |6 = Invalid $iFullPath
    ; |7 = Invalid $sExclude_List
    ; |8 = No files/folders found
    ; Author ........: Melba23 using SRE code from forums
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _RecFileListToArray($sInitialPath, $sInclude_List = "*", $iReturn = 0, $fRecur = 0, $fSort = 0, $sReturnPath = 1, $sExclude_List = "")

    [/autoit] [autoit][/autoit] [autoit]

    Local $asReturnList[100] = [0], $asFileMatchList[100] = [0], $asRootFileMatchList[100] = [0], $asFolderMatchList[100] = [0], $asFolderList[100] = [1]
    Local $sFolderSlash = "", $sInclude_List_Mask, $sExclude_List_Mask, $hSearch, $fFolder, $sRetPath = "", $sCurrentPath, $sName

    [/autoit] [autoit][/autoit] [autoit]

    ; Check valid path
    If Not FileExists($sInitialPath) Then Return SetError(1, 1, "")
    ; Check if folders should have trailing \ and ensure that $sInitialPath does have one
    If StringRight($sInitialPath, 1) = "\" Then
    $sFolderSlash = "\"
    Else
    $sInitialPath = $sInitialPath & "\"
    EndIf
    ; Add path to folder list
    $asFolderList[1] = $sInitialPath

    [/autoit] [autoit][/autoit] [autoit]

    ; Determine Filter mask for SRE check
    If $sInclude_List = "*" Then
    $sInclude_List_Mask = ".+" ; Set mask to exclude base folder with NULL name
    Else
    If StringRegExp($sInclude_List, "\\|/|:|\<|\>|\|") Then Return SetError(1, 2, "") ; Check For invalid characters within $sInclude_List
    $sInclude_List = StringReplace(StringStripWS(StringRegExpReplace($sInclude_List, "\s*;\s*", ";"), 3), ";", "|") ; Strip WS and insert | for ;
    $sInclude_List_Mask = "(?i)^(" & StringReplace(StringReplace(StringRegExpReplace($sInclude_List, "(\^|\$|\.)", "\\$1"), "?", "."), "*", ".*?") & ")\z" ; Convert to SRE pattern
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Determine Exclude mask for SRE check
    If $sExclude_List = "" Then
    $sExclude_List_Mask = ":" ; Set unmatchable mask
    Else
    If StringRegExp($sExclude_List, "\\|/|:|\<|\>|\|") Then Return SetError(1, 7, "") ; Check For invalid characters within $sInclude_List
    $sExclude_List = StringReplace(StringStripWS(StringRegExpReplace($sExclude_List, "\s*;\s*", ";"), 3), ";", "|") ; Strip WS and insert | for ;
    $sExclude_List_Mask = "(?i)^(" & StringReplace(StringReplace(StringRegExpReplace($sExclude_List, "(\^|\$|\.)", "\\$1"), "?", "."), "*", ".*?") & ")\z" ; Convert to SRE pattern
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Verify other parameter values
    If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 3, "")
    If Not ($fRecur = 0 Or $fRecur = 1) Then Return SetError(1, 4, "")
    If Not ($fSort = 0 Or $fSort = 1) Then Return SetError(1, 5, "")
    If Not ($sReturnPath = 0 Or $sReturnPath = 1 Or $sReturnPath = 2) Then Return SetError(1, 6, "")

    [/autoit] [autoit][/autoit] [autoit]

    ; Search in listed folders
    While $asFolderList[0] > 0

    [/autoit] [autoit][/autoit] [autoit]

    ; Set path to search
    $sCurrentPath = $asFolderList[$asFolderList[0]]
    ; Reduce folder array count
    $asFolderList[0] -= 1

    [/autoit] [autoit][/autoit] [autoit]

    ; Determine return path to add to file/folder name
    Switch $sReturnPath
    ; Case 0 ; Name only
    ; Leave as ""
    Case 1 ; Initial path not included
    $sRetPath = StringReplace($sCurrentPath, $sInitialPath, "")
    Case 2 ; Initial path included
    $sRetPath = $sCurrentPath
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    If $fSort Then

    [/autoit] [autoit][/autoit] [autoit]

    ; Get folder name
    $sName = StringRegExpReplace(StringReplace($sCurrentPath, $sInitialPath, ""), "(.+?\\)*(.+?)(\\.*?(?!\\))", "$2")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get Search handle
    $hSearch = FileFindFirstFile($sCurrentPath & "*")
    ; If folder empty move to next in list
    If $hSearch = -1 Then ContinueLoop

    [/autoit] [autoit][/autoit] [autoit]

    ; Search folder
    While 1
    $sName = FileFindNextFile($hSearch)
    ; Check for end of folder
    If @error Then ExitLoop
    ; Check for file - @extended set for subfolder in 3.3.1.1 +
    If @extended Then
    ; If recursive search, add subfolder to folder list
    If $fRecur Then _RFLTA_AddToList($asFolderList, $sCurrentPath & $sName & "\")

    [/autoit] [autoit][/autoit] [autoit]

    ; Add folder name if matched against Include/Exclude masks
    If StringRegExp($sName, $sInclude_List_Mask) And Not StringRegExp($sName, $sExclude_List_Mask) Then _
    _RFLTA_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash)

    [/autoit] [autoit][/autoit] [autoit]

    Else
    ; Add file name if matched against Include/Exclude masks
    If StringRegExp($sName, $sInclude_List_Mask) And Not StringRegExp($sName, $sExclude_List_Mask) Then
    If $sCurrentPath = $sInitialPath Then
    _RFLTA_AddToList($asRootFileMatchList, $sRetPath & $sName)
    Else
    _RFLTA_AddToList($asFileMatchList, $sRetPath & $sName)
    EndIf
    EndIf
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; Close current search
    FileClose($hSearch)

    [/autoit] [autoit][/autoit] [autoit]

    Else ; No sorting required

    [/autoit] [autoit][/autoit] [autoit]

    ; Get Search handle
    $hSearch = FileFindFirstFile($sCurrentPath & "*")
    ; If folder empty move to next in list
    If $hSearch = -1 Then ContinueLoop

    [/autoit] [autoit][/autoit] [autoit]

    ; Search folder
    While 1
    $sName = FileFindNextFile($hSearch)
    ; Check for end of folder
    If @error Then ExitLoop
    ; Check for subfolder - @extended set in 3.3.1.1 +
    $fFolder = @extended

    [/autoit] [autoit][/autoit] [autoit]

    ; If recursive search, add subfolder to folder list
    If $fRecur And $fFolder Then _RFLTA_AddToList($asFolderList, $sCurrentPath & $sName & "\")

    [/autoit] [autoit][/autoit] [autoit]

    ; Check file/folder type against required return value and file/folder name against Include/Exclude masks
    If $fFolder + $iReturn <> 2 And StringRegExp($sName, $sInclude_List_Mask) And Not StringRegExp($sName, $sExclude_List_Mask) Then
    ; Add final "\" to folders
    If $fFolder Then $sName &= $sFolderSlash
    _RFLTA_AddToList($asReturnList, $sRetPath & $sName)
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; Close current search
    FileClose($hSearch)

    [/autoit] [autoit][/autoit] [autoit]

    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    If $fSort Then

    [/autoit] [autoit][/autoit] [autoit]

    ; Check if any file/folders have been added
    If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 8, "")

    [/autoit] [autoit][/autoit] [autoit]

    Switch $iReturn
    Case 2 ; Folders only
    ; Correctly size folder match list
    ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
    ; Copy size folder match array
    $asReturnList = $asFolderMatchList
    ; Simple sort list
    _RFLTA_ArraySort($asReturnList)
    Case 1 ; Files only
    If $sReturnPath = 0 Then ; names only so simple sort suffices
    ; Combine file match lists
    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
    ; Simple sort combined file list
    _RFLTA_ArraySort($asReturnList)
    Else
    ; Combine sorted file match lists
    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)
    EndIf
    Case 0 ; Both files and folders
    If $sReturnPath = 0 Then ; names only so simple sort suffices
    ; Combine file match lists
    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
    ; Set correct count for folder add
    $asReturnList[0] += $asFolderMatchList[0]
    ; Resize and add file match array
    ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
    _RFLTA_ArrayConcatenate($asReturnList, $asFolderMatchList)
    ; Simple sort final list
    _RFLTA_ArraySort($asReturnList)
    Else
    ; Combine sorted file match lists
    _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)
    ; Add folder count
    $asReturnList[0] += $asFolderMatchList[0]
    ; Sort folder match list
    ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
    _RFLTA_ArraySort($asFolderMatchList)

    [/autoit] [autoit][/autoit] [autoit]

    ; Now add folders in correct place
    Local $iLastIndex = $asReturnList[0]
    For $i = $asFolderMatchList[0] To 1 Step -1
    ; Find first filename containing folder name
    Local $iIndex = _RFLTA_ArraySearch($asReturnList, $asFolderMatchList[$i])
    If $iIndex = -1 Then
    ; Empty folder so insert immediately above previous
    _RFLTA_ArrayInsert($asReturnList, $iLastIndex, $asFolderMatchList[$i])
    Else
    ; Insert folder at correct point above files
    _RFLTA_ArrayInsert($asReturnList, $iIndex, $asFolderMatchList[$i])
    $iLastIndex = $iIndex
    EndIf
    Next
    EndIf
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    Else ; No sort

    [/autoit] [autoit][/autoit] [autoit]

    ; Check if any file/folders have been added
    If $asReturnList[0] = 0 Then Return SetError(1, 8, "")

    [/autoit] [autoit][/autoit] [autoit]

    ; Remove any unused return list elements from last ReDim
    ReDim $asReturnList[$asReturnList[0] + 1]

    [/autoit] [autoit][/autoit] [autoit]

    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Return $asReturnList

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RecFileListToArray

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_AddToList
    ; Description ...: Add element to list which is resized if necessary
    ; Syntax ........: _RFLTA_AddToList(ByRef $asList, $sValue)
    ; Parameters ....: $asList - List to be added to
    ; $sValue - Value to add
    ; Return values .: None - array modified ByRef
    ; Author ........: Melba23
    ; Remarks .......: This function is used internally by _RecFileListToArray
    ; ===============================================================================================================================
    Func _RFLTA_AddToList(ByRef $asList, $sValue)

    [/autoit] [autoit][/autoit] [autoit]

    ; Increase list count
    $asList[0] += 1
    ; Double list size if too small (fewer ReDim needed)
    If UBound($asList) <= $asList[0] Then ReDim $asList[UBound($asList) * 2]
    ; Add value
    $asList[$asList[0]] = $sValue

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_AddToList

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_AddFileLists
    ; Description ...: Add internal arrays after resizing and optional sorting
    ; Syntax ........: _RFLTA_AddFileLists(ByRef $asReturnList, $asRootFileMatchList, $asFileMatchList[, $iSort = 0])
    ; Parameters ....: $asReturnList - Base list
    ; $asRootFileMatchList - First list to add
    ; $asFileMatchList - Second list to add
    ; $iSort - (Optional) Whether to sort lists before adding
    ; |$iSort = 0 (Default) No sort
    ; |$iSort = 1 Sort in descending alphabetical order
    ; Return values .: None - array modified ByRef
    ; Author ........: Melba23
    ; Remarks .......: This function is used internally by _RecFileListToArray
    ; ===============================================================================================================================
    Func _RFLTA_AddFileLists(ByRef $asReturnList, $asRootFileMatchList, $asFileMatchList, $iSort = 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; Correctly size root file match array
    ReDim $asRootFileMatchList[$asRootFileMatchList[0] + 1]
    ; Simple sort root file match array if required
    If $iSort = 1 Then _RFLTA_ArraySort($asRootFileMatchList)
    ; Copy root file match array
    $asReturnList = $asRootFileMatchList
    ; Add file match count
    $asReturnList[0] += $asFileMatchList[0]
    ; Correctly size file match array
    ReDim $asFileMatchList[$asFileMatchList[0] + 1]
    ; Simple sort file match array if required
    If $iSort = 1 Then _RFLTA_ArraySort($asFileMatchList)
    ; Add file match array
    _RFLTA_ArrayConcatenate($asReturnList, $asFileMatchList)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_AddFileLists

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_ArraySearch
    ; Description ...: Search array downwards for partial match
    ; Syntax ........: _RFLTA_ArraySearch(Const ByRef $avArray, $vValue)
    ; Parameters ....: $avArray - Array to search
    ; $vValue - PValue to Search for
    ; Return values .: Success: Index of array in which element was found
    ; Failure: returns -1
    ; Author ........: SolidSnake, gcriaco, Ultima
    ; Modified.......: Melba23
    ; Remarks .......: This function is used internally by _RecFileListToArray
    ; ===============================================================================================================================
    Func _RFLTA_ArraySearch(Const ByRef $avArray, $vValue)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To UBound($avArray) - 1
    If StringInStr($avArray[$i], $vValue) > 0 Then Return $i
    Next
    Return -1

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_ArraySearch

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_ArraySort
    ; Description ...: Wrapper for QuickSort function
    ; Syntax ........: _RFLTA_ArraySort(ByRef $avArray)
    ; Parameters ....: $avArray - Array to sort
    ; $pNew_WindowProc - Pointer to new WindowProc
    ; Return values .: None - array modified ByRef
    ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima
    ; Modified.......: Melba23
    ; Remarks .......: This function is used internally by _RecFileListToArray
    ; ===============================================================================================================================
    Func _RFLTA_ArraySort(ByRef $avArray)

    [/autoit] [autoit][/autoit] [autoit]

    Local $iStart = 1, $iEnd = UBound($avArray) - 1
    _RFLTA_QuickSort($avArray, $iStart, $iEnd)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_ArraySort

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_QuickSort
    ; Description ...: recursive array sort
    ; Syntax ........: _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)
    ; Parameters ....: $avArray - Array to sort in descending alphabetical order
    ; $iStart - Start index
    ; $iEnd - End index
    ; Return values .: None - array modified ByRef
    ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima
    ; Modified.......: Melba23
    ; Remarks .......: This function is used internally by _RFLTA_ArraySort
    ; ===============================================================================================================================
    Func _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)

    [/autoit] [autoit][/autoit] [autoit]

    Local $vTmp
    If ($iEnd - $iStart) < 15 Then
    Local $i, $j, $vCur
    For $i = $iStart + 1 To $iEnd
    $vTmp = $avArray[$i]
    If IsNumber($vTmp) Then
    For $j = $i - 1 To $iStart Step -1
    $vCur = $avArray[$j]
    If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop
    $avArray[$j + 1] = $vCur
    Next
    Else
    For $j = $i - 1 To $iStart Step -1
    If (StringCompare($vTmp, $avArray[$j]) >= 0) Then ExitLoop
    $avArray[$j + 1] = $avArray[$j]
    Next
    EndIf
    $avArray[$j + 1] = $vTmp
    Next
    Return
    EndIf
    Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)], $fNum = IsNumber($vPivot)
    Do
    If $fNum Then
    While ($avArray[$L] < $vPivot And IsNumber($avArray[$L])) Or (Not IsNumber($avArray[$L]) And StringCompare($avArray[$L], $vPivot) < 0)
    $L += 1
    WEnd
    While ($avArray[$R] > $vPivot And IsNumber($avArray[$R])) Or (Not IsNumber($avArray[$R]) And StringCompare($avArray[$R], $vPivot) > 0)
    $R -= 1
    WEnd
    Else
    While (StringCompare($avArray[$L], $vPivot) < 0)
    $L += 1
    WEnd
    While (StringCompare($avArray[$R], $vPivot) > 0)
    $R -= 1
    WEnd
    EndIf
    If $L <= $R Then
    $vTmp = $avArray[$L]
    $avArray[$L] = $avArray[$R]
    $avArray[$R] = $vTmp
    $L += 1
    $R -= 1
    EndIf
    Until $L > $R
    _RFLTA_QuickSort($avArray, $iStart, $R)
    _RFLTA_QuickSort($avArray, $L, $iEnd)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_QuickSort

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_ArrayConcatenate
    ; Description ...: Joins 2 arrays
    ; Syntax ........: _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)
    ; Parameters ....: $avArrayTarget - Base array
    ; $avArraySource - Array to add from element 1 onwards
    ; Return values .: None - array modified ByRef
    ; Author ........: Ultima
    ; Modified.......: Melba23
    ; Remarks .......: This function is used internally by _RecFileListToArray
    ; ===============================================================================================================================
    Func _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)

    [/autoit] [autoit][/autoit] [autoit]

    Local $iUBoundTarget = UBound($avArrayTarget) - 1, $iUBoundSource = UBound($avArraySource)
    ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
    For $i = 1 To $iUBoundSource - 1
    $avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]
    Next

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_ArrayConcatenate

    [/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _RFLTA_ArrayInsert
    ; Description ...: Insert element into array
    ; Syntax ........: _RFLTA_ArrayInsert(ByRef $avArray, $iElement, $vValue = "")
    ; Parameters ....: $avArray - Array to modify
    ; $iElement - Index position for insertion
    ; $vValue - Value to insert
    ; Return values .: None - array modified ByRef
    ; Author ........: Jos van der Zande, Ultima
    ; Modified.......: Melba23
    ; Remarks .......: This function is used internally by _RecFileListToArray
    ; ===============================================================================================================================
    Func _RFLTA_ArrayInsert(ByRef $avArray, $iElement, $vValue = "")

    [/autoit] [autoit][/autoit] [autoit]

    Local $iUBound = UBound($avArray) + 1
    ReDim $avArray[$iUBound]
    For $i = $iUBound - 1 To $iElement + 1 Step -1
    $avArray[$i] = $avArray[$i - 1]
    Next
    $avArray[$iElement] = $vValue

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_RFLTA_ArrayInsert

    [/autoit]


    Diese Funktion von Melba23 aus dem EN-Forum ermöglicht das ganz einfach:
    Suchpfad: C:\
    Suchpattern: *.exe
    Rekursion an.

    lg^^

  • Nach einem Gespräch in der SB mit dem Threadstarter habe ich noch eine Lösung, welche die Live-Aktualisierung des Fortschrittes ermöglicht (Die oben genannte Suche dauert ja ziemlich lange).
    Ich habe eine Funktion von BugFix aus diesem Thread ein wenig modifiziert und um eine Callback-Möglichkeit erweitert.
    Ist, denke ich, weitestgehend selbsterklärend.^^

    Spoiler anzeigen
    [autoit]


    #include<Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $ret = _GetFilesFolder_Rekursiv(@ProgramFilesDir, "_Output", 'exe', 0, 0)
    _ArrayDisplay($ret, 'Rekursiv alle au3-Dateien')

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Output($iCurrSize, $iFullSize, $sFile)
    ToolTip(Round(($iCurrSize / $iFullSize) * 100, 3) & "%" & @CRLF & $sFile, 0, 0)
    EndFunc ;==>_Output

    [/autoit] [autoit][/autoit] [autoit]

    ;==================================================================================================
    ; Function Name: _GetFilesFolder_Rekursiv($sPath [, $sExt='*' [, $iDir=-1 [, $iRetType=0 ,[$sDelim='0']]]])
    ; Description: Rekursive Auflistung von Dateien und/oder Ordnern
    ; Parameter(s): $sPath der Basispfad für die Auflistung ('.' -aktueller Pfad, '..' -Parentpfad)
    ; $sCallback Callback-Funktion für den aktuellen Status
    ; $sExt Erweiterung für Dateiauswahl '*' oder -1 für alle (Standard)
    ; $iDir -1 Dateien+Ordner(Standard), 0 nur Dateien, 1 nur Ordner
    ; optional: $iRetType 0 gibt Array, 1 gibt String zurück
    ; optional: $sDelim legt Trennzeichen für Stringrückgabe fest
    ; 0 -@CRLF (Standard) 1 -@CR 2 -@LF 3 -';' 4 -'|'
    ; Return Value(s): Array (Standard) od. String mit den gefundenen Pfaden der Dateien und/oder Ordner
    ; Array[0] enthält die Anzahl der gefundenen Dateien/Ordner
    ; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
    ; Modified ......: chesstiger (Progress-Callback)
    ;==================================================================================================
    Func _GetFilesFolder_Rekursiv($sPath, $sCallback, $sExt = '*', $iDir = -1, $iRetType = 0, $sDelim = '0')
    Global $oFSO = ObjCreate('Scripting.FileSystemObject')
    Global $strFiles = ''
    Switch $sDelim
    Case '1'
    $sDelim = @CR
    Case '2'
    $sDelim = @LF
    Case '3'
    $sDelim = ';'
    Case '4'
    $sDelim = '|'
    Case Else
    $sDelim = @CRLF
    EndSwitch
    If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
    If $sExt = -1 Then $sExt = '*'
    If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1

    [/autoit] [autoit][/autoit] [autoit]

    Local $iCurrSize = 0, $iFullSize = DirGetSize($sPath)

    [/autoit] [autoit][/autoit] [autoit]

    _ShowSubFolders($oFSO.GetFolder($sPath), $sExt, $iDir, $sDelim, $iCurrSize, $iFullSize, $sCallback)
    If $iRetType = 0 Then
    Local $aOut
    $aOut = StringSplit(StringTrimRight($strFiles, StringLen($sDelim)), $sDelim, 1)
    If $aOut[1] = '' Then
    ReDim $aOut[1]
    $aOut[0] = 0
    EndIf
    Return $aOut
    Else
    Return StringTrimRight($strFiles, StringLen($sDelim))
    EndIf
    EndFunc ;==>_GetFilesFolder_Rekursiv

    [/autoit] [autoit][/autoit] [autoit]

    Func _ShowSubFolders($Folder, $Ext, $Dir, $Delim, ByRef $iCurrSize, $iFullSize, $sCallback)
    If Not IsDeclared("strFiles") Then Global $strFiles = ''
    If ($Dir = -1) Or ($Dir = 0) Then
    For $file In $Folder.Files
    If $Ext <> '*' Then
    If StringRight($file.Name, StringLen($Ext)) = $Ext Then
    $strFiles &= $file.Path & $Delim
    $sCallFileName = $file.Path
    Else
    $sCallFileName = 0
    EndIf
    Else
    $strFiles &= $file.Path & $Delim
    $sCallFileName = $file.Path
    EndIf
    $iCurrSize += $file.Size
    Call($sCallback, $iCurrSize, $iFullSize, $sCallFileName)
    Next
    EndIf
    For $Subfolder In $Folder.SubFolders
    If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
    _ShowSubFolders($Subfolder, $Ext, $Dir, $Delim, $iCurrSize, $iFullSize, $sCallback)
    Next
    EndFunc ;==>_ShowSubFolders

    [/autoit]

    lg

    • Offizieller Beitrag

    Das DirGetSize dauert ja schon "ewig". Da ist meine Funktion bereits mit dem einlesen fertig. ;)

    Spoiler anzeigen
    [autoit]


    #include <Array.au3>
    $iTimer = TimerInit()
    $sDir = @ProgramFilesDir
    $ret = _RecursiveFileListToArray($sDir, '\.exe\z', 1, 1, True)
    ConsoleWrite(TimerDiff($iTimer) & @CR)
    If IsArray($ret) Then
    _ArrayDisplay($ret)
    Else
    ConsoleWrite($ret)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _RecursiveFileListToArray($sPath[, $sPattern][, $iFlag][, $iFormat][, $fRecursion][, $sDelim])
    ; Description:: gibt Verzeichnisse (rekursiv) und/oder Dateien zurück, die einem RegExp-Pattern entsprechen
    ; Parameter(s): $sPath = Startverzeichnis
    ; $sPattern = ein beliebiges RexExp-Pattern für die Auswahl
    ; $iFlag = Auswahl
    ; 0 = Dateien & Verzeichnisse
    ; 1 = nur Dateien
    ; 2 = nur Verzeichnisse
    ; $iFormat = Rückgabeformat
    ; 0 = String
    ; 1 = Array mit [0] = Anzahl
    ; 2 = Nullbasiertes Array
    ; $fRecursion = Verzeichnisse rekursiv durchsuchen
    ; False = Nein
    ; True = Ja
    ; $sDelim = Trennzeichen für die String-Rückgabe
    ; Requirement(s): AutoIt 3.3.0.0
    ; Return Value(s): Array/String mit den gefundenen Dateien/Verzeichnissen
    ; Author(s): Oscar (http://www.autoit.de)
    ; Anregungen von: bernd670 (http://www.autoit.de)
    ; und: AspirinJunkie (http://www.autoit.de)
    ;===============================================================================
    Func _RecursiveFileListToArray($sPath, $sPattern = '', $iFlag = 0, $iFormat = 1, $fRecursion = True, $sDelim = @CRLF, $fOpenDLL = True)
    Local $hSearch, $sFile, $sReturn = '', $aD
    Local Static $hDll
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $hSearch = FileFindFirstFile($sPath & '*')
    If Not @error And $hSearch <> -1 Then
    If $fOpenDLL Then $hDll = DllOpen('kernel32.dll')
    While True
    $sFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    If @extended Then
    $aD = DllCall($hDll, 'dword', 'GetFileAttributesW', 'wstr', $sPath & $sFile)
    If @error Or BitAND($aD[0], 0x400) Then ContinueLoop
    If StringRegExp($sPath & $sFile, $sPattern) And ($iFlag = 0 Or $iFlag = 2) Then $sReturn &= $sPath & $sFile & '\' & $sDelim
    If $fRecursion Then $sReturn &= _RecursiveFileListToArray($sPath & $sFile & '\', $sPattern, $iFlag, 0, True, $sDelim, False)
    ContinueLoop
    EndIf
    If StringRegExp($sFile, $sPattern) And ($iFlag = 0 Or $iFlag = 1) Then $sReturn &= $sPath & $sFile & $sDelim
    WEnd
    FileClose($hSearch)
    If $fOpenDLL Then DllClose($hDll)
    EndIf
    If $iFormat = 2 Then $iFormat = 3
    If $iFormat And $sReturn = '' Then Return StringSplit($sReturn, '', $iFormat)
    If $iFormat Then Return StringSplit(StringTrimRight($sReturn, StringLen($sDelim)), $sDelim, $iFormat)
    Return $sReturn
    EndFunc

    [/autoit]
    • Offizieller Beitrag

    Was hat das aber für einen Sinn, wenn ich auf den Anfang des Einlesens mit Live-Aktualisierung bereits solange warten muss, wie bei einer anderen Funktion bereits das gesamte Einlesen dauert.
    Ich weiß, dass es sinnvoll ist den Benutzer anzuzeigen wie weit das Programm gerade ist, aber eine Prozentanzeige ist halt dahingehend sehr schlecht, weil man erstmal die 100% rausbekommen muss.
    Eine Anzeige ("Bitte warten...dauert u.U. einige Minuten") wäre wohl meist ausreichend. Wenn unbedingt die Prozentanzeige gewünscht ist, dann auf keinen Fall bei jeder Datei aktualisieren, sondern mittels Timer nur alle 200ms oder so.
    Das würde dann auch das flackern minimieren.

    • Offizieller Beitrag

    Um dem Benutzer den Fortschritt anzuzeigen, könnte man ja auch das aktuell durchsuchte Verzeichnis per ToolTip anzeigen.
    Hier mal mit Aktualisierungsintervall von 50 ms:

    Spoiler anzeigen
    [autoit]


    #include <Array.au3>
    $iTimer = TimerInit()
    $sDir = @ProgramFilesDir
    $ret = _RecursiveFileListToArray($sDir, '\.exe\z', 1, 1, True)
    ToolTip('')
    ConsoleWrite(TimerDiff($iTimer) & @CR)
    If IsArray($ret) Then
    _ArrayDisplay($ret)
    Else
    ConsoleWrite($ret)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _RecursiveFileListToArray($sPath[, $sPattern][, $iFlag][, $iFormat][, $fRecursion][, $sDelim])
    ; Description:: gibt Verzeichnisse (rekursiv) und/oder Dateien zurück, die einem RegExp-Pattern entsprechen
    ; Parameter(s): $sPath = Startverzeichnis
    ; $sPattern = ein beliebiges RexExp-Pattern für die Auswahl
    ; $iFlag = Auswahl
    ; 0 = Dateien & Verzeichnisse
    ; 1 = nur Dateien
    ; 2 = nur Verzeichnisse
    ; $iFormat = Rückgabeformat
    ; 0 = String
    ; 1 = Array mit [0] = Anzahl
    ; 2 = Nullbasiertes Array
    ; $fRecursion = Verzeichnisse rekursiv durchsuchen
    ; False = Nein
    ; True = Ja
    ; $sDelim = Trennzeichen für die String-Rückgabe
    ; Requirement(s): AutoIt 3.3.0.0
    ; Return Value(s): Array/String mit den gefundenen Dateien/Verzeichnissen
    ; Author(s): Oscar (http://www.autoit.de)
    ; Anregungen von: bernd670 (http://www.autoit.de)
    ; und: AspirinJunkie (http://www.autoit.de)
    ;===============================================================================
    Func _RecursiveFileListToArray($sPath, $sPattern = '', $iFlag = 0, $iFormat = 1, $fRecursion = True, $sDelim = @CRLF, $fOpenDLL = True)
    Local $hSearch, $sFile, $sReturn = '', $aD
    Local Static $hDll
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $hSearch = FileFindFirstFile($sPath & '*')
    If Not @error And $hSearch <> -1 Then
    If $fOpenDLL Then $hDll = DllOpen('kernel32.dll')
    While True
    $sFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    If @extended Then
    $aD = DllCall($hDll, 'dword', 'GetFileAttributesW', 'wstr', $sPath & $sFile)
    If @error Or BitAND($aD[0], 0x400) Then ContinueLoop
    If StringRegExp($sPath & $sFile, $sPattern) And ($iFlag = 0 Or $iFlag = 2) Then $sReturn &= $sPath & $sFile & '\' & $sDelim
    If $fRecursion Then $sReturn &= _RecursiveFileListToArray(_ShowProgress($sPath & $sFile & '\'), $sPattern, $iFlag, 0, True, $sDelim, False)
    ContinueLoop
    EndIf
    If StringRegExp($sFile, $sPattern) And ($iFlag = 0 Or $iFlag = 1) Then $sReturn &= $sPath & $sFile & $sDelim
    WEnd
    FileClose($hSearch)
    If $fOpenDLL Then DllClose($hDll)
    EndIf
    If $iFormat = 2 Then $iFormat = 3
    If $iFormat And $sReturn = '' Then Return StringSplit($sReturn, '', $iFormat)
    If $iFormat Then Return StringSplit(StringTrimRight($sReturn, StringLen($sDelim)), $sDelim, $iFormat)
    Return $sReturn
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ShowProgress($sPath)
    Local Static $iTimer2 = TimerInit()
    If TimerDiff($iTimer2) > 50 Then
    $iTimer2 = TimerInit()
    ToolTip($sPath, 20, 20, 'Suche exe-Dateien...', 1, 5)
    EndIf
    Return $sPath
    EndFunc

    [/autoit]