#include <Array.au3>
#include <File.au3>


While ProcessExists("chrome.exe")
	ProcessClose("chrome.exe")
WEnd

#cs
===========================================================================================================================================

_GetFiles
---------

Version:	1.0

Autor:		Shadowigor

Funktion:	Gibt die Dateistruktur eines Pfades an (mit Filter)

Parameter:	$sPathFull	Der zu durchsuchende Pfad (z.B C:\Users\Benutzer\*.* oder C:\Users\Benutzer\*.jpg)
			$fFlag		0 > Wird in Files.txt geschrieben
						1 > Gibt es als Array zurück
						2 > Gibt es als String zurück

Bemerkung:	Setzt @error und gibt "Nothing Found!" zurück (bzw. schreibt es in die Datei) wenn nichts gefunden wurde
			Gezielte Dateisuche wird noch nicht unterstützt.

===========================================================================================================================================
#ce

Func _GetFiles($sPathFull, $fFlag = 0)

	Local $aSubdirTmp[1], $aSubdir[1], $iLengh, $sPath, $sFile, $aFileList[1], $i, $sFileList, $sSubPath, $aFiles[1]

	$iLengh = StringInStr($sPathFull, "\", 0, -1)
	$sPath = StringLeft($sPathFull, $iLengh)
	$sFile = StringTrimLeft($sPathFull, $iLengh + 1)
	$iLengh = StringLen($sFile)

	If Not FileExists($sPath) Then
		If $fFlag = 0 Then
			$hFileWrite = FileOpen(@ScriptDir & "\Files.txt", 2)
			FileWrite($hFileWrite, "Nothing Found!")
			FileClose($hFileWrite)
			Return SetError(1)
		EndIf
		SetError(1)
		Return "Nothing Found!"
	EndIf

	$aFileList = _FileListToArray($sPath)

	For $i = 1 To $aFileList[0]
		If StringInStr(FileGetAttrib($sPath & $aFileList[$i]), "D") <> 0 Then
			_ArrayAdd($aSubdirTmp, $sPath & $aFileList[$i])
			If $sFile = ".*" Then _ArrayAdd($aFiles, $sPath & $aFileList[$i])
		ElseIf ($sFile = ".*") Or (StringRight($aFileList[$i], $iLengh) = $sFile) Then
			_ArrayAdd($aFiles, $sPath & $aFileList[$i])
		EndIf
	Next

	While UBound($aSubdirTmp) > 1
		$sSubPath = $aSubdirTmp[UBound($aSubdirTmp) - 1]
		$aFileList = _FileListToArray(_ArrayPop($aSubdirTmp))
		If IsArray($aFileList) Then
			For $i = 1 To $aFileList[0]
				If StringInStr(FileGetAttrib($sSubPath & "\" & $aFileList[$i]), "D") <> 0 Then
					_ArrayInsert($aSubdirTmp, 1, $sSubPath & "\" & $aFileList[$i])
					If $sFile = ".*" Then _ArrayInsert($aFiles, 1, $sSubPath & "\" & $aFileList[$i])
				ElseIf ($sFile = ".*") Or (StringRight($aFileList[$i], $iLengh) = $sFile) Then
					_ArrayInsert($aFiles, 1, $sSubPath & "\" & $aFileList[$i])
				EndIf
			Next
		EndIf
	WEnd

	If $fFlag = 1 Then Return $aFiles
	$sFileList = _ArrayToString($aFiles, @CRLF)
	If $fFlag = 2 Then Return $sFileList
	$hFileWrite = FileOpen(@ScriptDir & "\Files.txt", 2)
	FileWrite($hFileWrite, $sFileList)
	FileClose($hFileWrite)

EndFunc   ;==>_GetFiles