1 | #include<array.au3> |
---|
2 | $iflag = 0 |
---|
3 | |
---|
4 | ; Beta Version ------------------------------- |
---|
5 | $timer = TimerInit() |
---|
6 | For $j = 1 to 10 |
---|
7 | $x = _FileListToArray2(@SystemDir,"*",$iflag) |
---|
8 | Next |
---|
9 | $timer1 = TimerDiff ($timer) |
---|
10 | |
---|
11 | ; Modified Beta Version ---------------------- |
---|
12 | $timer = TimerInit() |
---|
13 | For $j = 1 to 10 |
---|
14 | $x = _FileListToArray3(@SystemDir,"*",$iflag) |
---|
15 | Next |
---|
16 | $timer2 = TimerDiff ($timer) |
---|
17 | |
---|
18 | MsgBox (0, "", $timer1 & " " & $timer2) |
---|
19 | ;_ArrayDisplay($x) |
---|
20 | |
---|
21 | ; ------------------------------------------------ |
---|
22 | Func _FileListToArray2($sPath, $sFilter = "*", $iFlag = 0) |
---|
23 | Local $hSearch, $sFile, $asFileList[1] |
---|
24 | If Not FileExists($sPath) Then Return SetError(1, 1, "") |
---|
25 | If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringInStr($sFilter, "|")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "") |
---|
26 | If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "") |
---|
27 | If (StringMid($sPath, StringLen($sPath), 1) = "\") Then $sPath = StringTrimRight($sPath, 1) ; needed for Win98 for x:\ root dir |
---|
28 | $hSearch = FileFindFirstFile($sPath & "\" & $sFilter) |
---|
29 | If $hSearch = -1 Then Return SetError(4, 4, "") |
---|
30 | While 1 |
---|
31 | $sFile = FileFindNextFile($hSearch) |
---|
32 | If @error Then |
---|
33 | SetError(0) |
---|
34 | ExitLoop |
---|
35 | EndIf |
---|
36 | If $iFlag = 1 And @extended Then |
---|
37 | ContinueLoop ; File only |
---|
38 | Else |
---|
39 | If $iFlag = 2 And @extended = 0 Then ContinueLoop ; folder only |
---|
40 | EndIf |
---|
41 | $asFileList[0] += 1 |
---|
42 | If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2] |
---|
43 | $asFileList[$asFileList[0]] = $sFile |
---|
44 | WEnd |
---|
45 | FileClose($hSearch) |
---|
46 | ReDim $asFileList[$asFileList[0] + 1] ; Trim unused slots |
---|
47 | Return $asFileList |
---|
48 | EndFunc ;==>_FileListToArray |
---|
49 | |
---|
50 | Func _FileListToArray3($sPath, $sFilter = "*", $iFlag = 0) |
---|
51 | Local $hSearch, $sFile, $asFileList[64], $aMax = 64 |
---|
52 | If Not FileExists($sPath) Then Return SetError(1, 1, "") |
---|
53 | If StringRegexp($sFilter, "[\\/:<>|]") Or (Not StringStripWS($sFilter, 8)) Then Return SetError(2, 2, "") |
---|
54 | If (StringMid($sPath, StringLen($sPath), 1) = "\") Then $sPath = StringTrimRight($sPath, 1) ; needed for Win98 for x:\ root dir |
---|
55 | $hSearch = FileFindFirstFile($sPath & "\" & $sFilter) |
---|
56 | If $hSearch = -1 Then Return SetError(4, 4, "") |
---|
57 | Switch $iFlag |
---|
58 | Case 0; Files and Folders |
---|
59 | While 1 |
---|
60 | $sFile = FileFindNextFile($hSearch) |
---|
61 | If @error Then ExitLoop |
---|
62 | $asFileList[0] += 1 |
---|
63 | If $asFileList[0] = $aMax Then |
---|
64 | $aMax *= 2 |
---|
65 | ReDim $asFileList[$aMax] |
---|
66 | EndIf |
---|
67 | $asFileList[$asFileList[0]] = $sFile |
---|
68 | WEnd |
---|
69 | Case 1; Files Only |
---|
70 | While 1 |
---|
71 | $sFile = FileFindNextFile($hSearch) |
---|
72 | If @error Then ExitLoop |
---|
73 | If @extended Then ContinueLoop ; bypass folder |
---|
74 | $asFileList[0] += 1 |
---|
75 | If $asFileList[0] = $aMax Then |
---|
76 | $aMax *= 2 |
---|
77 | ReDim $asFileList[$aMax] |
---|
78 | EndIf |
---|
79 | $asFileList[$asFileList[0]] = $sFile |
---|
80 | WEnd |
---|
81 | Case 2; Folders Only |
---|
82 | While 1 |
---|
83 | $sFile = FileFindNextFile($hSearch) |
---|
84 | If @error Then ExitLoop |
---|
85 | If @extended = 0 Then ContinueLoop ; bypass file |
---|
86 | $asFileList[0] += 1 |
---|
87 | If $asFileList[0] = $aMax Then |
---|
88 | $aMax *= 2 |
---|
89 | ReDim $asFileList[$aMax] |
---|
90 | EndIf |
---|
91 | $asFileList[$asFileList[0]] = $sFile |
---|
92 | WEnd |
---|
93 | Case Else |
---|
94 | Return SetError(3, 3, "") |
---|
95 | EndSwitch |
---|
96 | FileClose($hSearch) |
---|
97 | ReDim $asFileList[$asFileList[0] + 1] ; Trim unused slots |
---|
98 | Return $asFileList |
---|
99 | EndFunc ;==>_FileListToArray |
---|