Vielleicht gibt es massig solcher Skripte, aber das hier ist mit echter Rekursion (Funktion ruft sich selbst wieder auf)!
Spoiler anzeigen
#include <Array.au3>
Dim $ergebnis[1]
$path = @WindowsDir
[/autoit] [autoit][/autoit] [autoit]If StringRight($path, 1) <> "\" Then $path &= "\"
$depth = StringReplace($path, "\", "\")
$depth = @extended - 1
If StringLeft($path, 2) = "\\" Then $depth -= 2
$file = ".log" ;to search for any file use "*"
;~ $ergebnis = File_Seeker($path, $file, $ergebnis, 0, 1) ;searchs for ".log" (exact search)
;~ $ergebnis = File_Seeker($path, $file, $ergebnis, 0, 0, 1, 0) ;searchs for "*.log*" recursively but dir names are excluded
;~ $ergebnis = File_Seeker($path, $file, $ergebnis, 0, 0, 0, 0) ;searchs for "*.log*" but not recursive and no dir names
$ergebnis = File_Seeker($path, $file, $ergebnis, 1, 0, 1) ;searchs for files with extension .log but dir names are excluded
If Not @error Then
;~ _ArraySort($ergebnis)
_ArrayDisplay($ergebnis)
;~ Local $log
;~ For $i = 1 To UBound($ergebnis) - 1
;~ $log &= $ergebnis[$i] & @CRLF
;~ Next
;~ $file = FileOpen(@ScriptDir & "\Ergebnis.log", 1)
;~ FileWrite($file, $log)
;~ FileClose($file)
EndIf
Exit
[/autoit] [autoit][/autoit] [autoit];==================================================================================================
; Function Name: File_Seeker($path, $file, $array)
; Description: searchs for a file recursively on given drive
; Parameters: $path: path where to search
; $file: filename to search for
; $array: to save the search results
; Optional:
; $ext: search for file extension, e.g. .mp3
; $exact: to search for exact file name (not case sensitive)
; $rec: to search recursively for files and folders
; $folder: include also folder names to search pattern
; $maxr: maximum of recursion depth, 0 = maxiumum
; Return Value(s): an array with the full path of the files, $array[0] = amount of found files
; Version: v0.85 Build 2010-12-01 Beta
; Author(s): UEZ
;==================================================================================================
Func File_Seeker($path, $file, ByRef $aResults, $ext = 0, $exact = 0, $rec = 1, $folder = 0, $maxr = 0)
Local $extended, $d
If Not IsInt($maxr) Then Return SetError(2)
If $file <> "" And IsArray($aResults) And BitAND($ext, $exact) <> 1 Then
If StringLeft($path, 2) = "\\" Or (StringRegExp(StringLeft($path, 1), "(?i:[A-Z])") And StringMid($path, 2, 1) = ":") Then
If $maxr Then
$d = StringReplace($path, "\", "\")
$d = @extended - 1
If StringLeft($path, 2) = "\\" Then $d -= 2
$d -= $depth
;~ ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $d = ' & $d & ">=" & $maxr & ": " & $path & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If $d > $maxr Then Return SetError(5)
EndIf
If StringRight($path, 1) <> "\" Then $path &= "\"
Local $seek, $suffix = ""
Local $search = FileFindFirstFile($path & "*")
If $search = -1 Then
Return SetError(3)
EndIf
While 1
$seek = FileFindNextFile($search)
$extended = @extended
If @error Then ExitLoop
If $extended And $rec Then File_Seeker($path & $seek & "\", $file, $aResults, $ext, $exact, $rec, $folder, $maxr)
If $exact And Not $ext Then
If $seek = $file Then _ArrayAdd($aResults, $path & $seek)
Else
If $ext Then
If StringRegExp($seek, "(?i:\" & $file & "+$\b)") And StringLeft($file, 1) = "." Then
If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek)
EndIf
Else
If $file = "*" Then
If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek)
Else
If StringInStr($file, ".") Then
If StringRegExp($seek, "(?i:\" & $file & ")+") Then
If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek)
EndIf
Else
If StringRegExp($seek, "(?i:" & $file & ")+") Then
If ($extended And $folder) Or Not $extended Then _ArrayAdd($aResults, $path & $seek)
EndIf
EndIf
EndIf
EndIf
EndIf
WEnd
FileClose($search)
$aResults[0] = UBound($aResults) - 1
Return SetError(0, 0, $aResults)
Else
Return SetError(4)
EndIf
Else
Return SetError(1)
EndIf
EndFunc
Kritik? Bugs?
Gruß,
UEZ
PS: na ja, hab' das Forum nach sowas durchsucht und musste feststellen, dass ich das Rad neu erfunden habe. Hier meine Variante