| 1 | Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0) |
|---|
| 2 | Local $hSearch, $sFile, $asFileList[1] |
|---|
| 3 | If Not FileExists($sPath) Then Return SetError(1, 1, "") |
|---|
| 4 | If StringRegexp($sFilter, "[\\/:<>|]") Or (Not StringStripWS($sFilter, 8)) Then Return SetError(2, 2, "") |
|---|
| 5 | If (StringMid($sPath, StringLen($sPath), 1) = "\") Then $sPath = StringTrimRight($sPath, 1); needed for Win98 for x:\ root dir |
|---|
| 6 | $hSearch = FileFindFirstFile($sPath & "\" & $sFilter) |
|---|
| 7 | If $hSearch = -1 Then Return SetError(4, 4, "") |
|---|
| 8 | Switch $iFlag |
|---|
| 9 | Case 0 ; Filas and folders |
|---|
| 10 | While 1 |
|---|
| 11 | $sFile = FileFindNextFile($hSearch) |
|---|
| 12 | If @error Then |
|---|
| 13 | SetError(0) |
|---|
| 14 | ExitLoop |
|---|
| 15 | EndIf |
|---|
| 16 | $asFileList[0] += 1 |
|---|
| 17 | If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2] |
|---|
| 18 | $asFileList[$asFileList[0]] = $sFile |
|---|
| 19 | WEnd |
|---|
| 20 | Case 1 ; Files Only |
|---|
| 21 | While 1 |
|---|
| 22 | $sFile = FileFindNextFile($hSearch) |
|---|
| 23 | If @error Then |
|---|
| 24 | SetError(0) |
|---|
| 25 | ExitLoop |
|---|
| 26 | EndIf |
|---|
| 27 | If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") Then ContinueLoop |
|---|
| 28 | $asFileList[0] += 1 |
|---|
| 29 | If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2] |
|---|
| 30 | $asFileList[$asFileList[0]] = $sFile |
|---|
| 31 | WEnd |
|---|
| 32 | Case 2 ; Folders Only |
|---|
| 33 | While 1 |
|---|
| 34 | $sFile = FileFindNextFile($hSearch) |
|---|
| 35 | If @error Then |
|---|
| 36 | SetError(0) |
|---|
| 37 | ExitLoop |
|---|
| 38 | EndIf |
|---|
| 39 | If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop |
|---|
| 40 | $asFileList[0] += 1 |
|---|
| 41 | If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2] |
|---|
| 42 | $asFileList[$asFileList[0]] = $sFile |
|---|
| 43 | WEnd |
|---|
| 44 | Case Else |
|---|
| 45 | Return SetError(3, 3, "") |
|---|
| 46 | EndSwitch |
|---|
| 47 | FileClose($hSearch) |
|---|
| 48 | ReDim $asFileList[$asFileList[0] + 1]; Trim unused slots |
|---|
| 49 | Return $asFileList |
|---|
| 50 | EndFunc ;==>_FileListToArray |
|---|