Ticket #834: _FileListToArrayFaster1e.au3

File _FileListToArrayFaster1e.au3, 25.1 KB (added by Rudi, on Feb 23, 2009 at 11:01:10 AM)

_FileListToArrayFaster1e.au3

Line 
1; _FileListToArrayFaster1e.au3
2#include-once
3#include<array.au3>;for _ArrayToString() and _ArrayInsert()
4;===============================================================================
5;
6; Description: lists all files and folders in a specified path
7; Syntax: _FileListToArray($s_Path, $s_Filter = "*", $i_Flag = 0)
8; Parameter(s): $s_Path = Path to generate filelist for
9; $s_Filter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
10; $i_Flag = determines whether to return file or folders or both
11; $i_Flag=0(Default) Return both files and folders
12; $i_Flag=1 Return files Only
13; $i_Flag=2 Return Folders Only
14; $i_Recurse = Indicate whether recursion to subfolders required
15; $i_Recurse=0(Default) No recursion to subfolders
16; $i_Recurse=1 recursion to subfolders
17; $i_BaseDir = Indicate whether base directory name included in returned elements
18; $i_BaseDir=0 base directory name not included
19; $i_BaseDir=1 (Default) base directory name included
20; $s_Exclude= The Exclude filter to use. "WildCards" For details
21;
22; Requirement(s): None
23; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
24; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
25; @Error=1 Path not found or invalid
26; @Error=2 Invalid $s_Filter
27; @Error=3 Invalid $i_Flag
28; @Error=4 No File(s) Found
29;
30; Author(s): randallc <randallc@ozemail.com.au>; modified from SolidSnake and big_daddy and SmoKE_N and GEOsoft!
31; Note(s): The array returned is one-dimensional and is made up as follows:
32; $array[0] = Number of Files\Folders returned
33; $array[1] = 1st File\Folder
34; $array[2] = 2nd File\Folder
35; $array[3] = 3rd File\Folder
36; $array[n] = nth File\Folder
37;
38;===============================================================================
39Func _FileListToArray3($sPath, $sFilter = "*", $iFlag = 0, $iRecurse = 0, $iBaseDir = 1, $sExclude = "", $i_deleteduplicate = 1)
40 ;Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $iRecurse = False, $iBaseDir = 1, $sExclude = '')
41 ;Declare local variables
42 Local $hSearch, $sFile, $sFileString, $asList[1], $sep = "|", $sFileString1, $sFilter1 = $sFilter
43
44 ;Set default filter to wildcard
45 If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*"
46
47 ;Strip trailing slash from search path
48 If StringRight($sPath, 1) == "\" Then $sPath = StringTrimRight($sPath, 1)
49
50 ;Ensure search path exists
51 If Not FileExists($sPath) Then Return SetError(1, 1, "")
52
53 ;Return error if special characters are found in filter
54 If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
55
56 ;Only allow 0,1,2 for flag options
57 If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "");~ $sFilter = StringReplace("*" & $sFilter & "*", "**", "*")
58
59 ;Append pipe to file filter if no semi-colons and pipe symbols are found
60;~ If Not StringInStr($sFilter, ';') And Not StringInStr($sFilter, '|') And Not StringInStr($sFilter, ',') Then $sFilter &= "|"
61 $sFilter &= "|"
62 ;Determine seperator character
63 If StringInStr($sFilter, ';') Then $sep = ";" ;$sFilter &= ';'
64 If StringInStr($sFilter, ',') Then $sep = "," ;$sFilter &= ';'
65
66 ;Declare local variables, Implode file filter
67 Local $aFilterSplit = StringSplit(StringStripWS($sFilter, 8), $sep), $sRead, $sHoldSplit, $arFolders[2] = [ $sPath, ""];~ $cw = ConsoleWrite("UBound($aFilterSplit) =" & UBound($aFilterSplit) & @LF)
68
69 If $sExclude <> "" Then $sExclude = "(?i)" & StringReplace(StringReplace(StringReplace($sExclude, ".", "\."), "*", ".*"), "?", ".");change the filters to RegExp filters
70
71 ;If recursion is desired, build an array of all sub-folders in search path (eliminates the need to run a conditional statement against FileAttrib)
72 If $iRecurse Then;$cw = ConsoleWrite("UBound($aFilterSplit) =" & UBound($aFilterSplit) & @LF)
73
74 ;if folders only, build string ($sFileString1) of foldernames within search path, recursion and exclusion options are passed from main function
75 If $iFlag = 2 Then _FileListToArrayFolders($sPath, $sFileString1, "*", $iRecurse, $sExclude)
76
77 ;if not folders only, Build string ($sFileString1) of foldernames within search path, recursion (not exclusion, as would exclude some folders from subsequent filesearch) options are passed from main function
78;~ If StringTrimRight($sFilter, 1) <> "*" And StringTrimRight($sFilter, 1) <> "*.*" Then
79 If $iFlag <> 2 And StringTrimRight($sFilter, 1) <> "*" And StringTrimRight($sFilter, 1) <> "*.*" Then
80 _FileListToArrayFolders($sPath, $sFileString1, "*", $iRecurse, "")
81
82 ;Implode folder string
83 Local $arFolders = StringSplit(StringTrimRight($sFileString1, 1), "*")
84
85 ;Store search path in first element
86 $arFolders[0] = $sPath
87 EndIf
88 EndIf
89;~ If StringTrimRight($sFilter, 1) == "*" Or StringTrimRight($sFilter, 1) == "*.*" And $iRecurse Then
90 If $iFlag <> 2 And (StringTrimRight($sFilter, 1) == "*" Or StringTrimRight($sFilter, 1) == "*.*") And $iRecurse Then
91 If $iFlag = 1 Then
92 _FileListToArrayRecFiles($sPath, $sFileString, "*")
93 ElseIf $iFlag = 0 Then
94 _FileListToArrayRecAll($sPath, $sFileString, "*")
95 EndIf
96 Else;If ($iFlag <> 2) then
97;~ ConsoleWrite("LOOP folders" & @LF)
98;~ ConsoleWrite("$iFlag=" & $iFlag & @LF)
99
100 ;Loop through folder array
101 For $iCF = 0 To UBound($arFolders) - 1; $cw = ConsoleWrite("$iCF=" & $iCF & " $arFolders[$iCF] =" & @LF & $arFolders[$iCF] & @LF)
102
103 ;Verify folder name isn't just whitespace
104 If StringStripWS($arFolders[$iCF], 8) = '' Then ContinueLoop
105
106 ;Loop through file filters
107 For $iCC = 1 To UBound($aFilterSplit) - 1
108
109 ;Verify file filter isn't just whitespace
110 If StringStripWS($aFilterSplit[$iCC], 8) = '' Then ContinueLoop
111
112 ;Append asterisk to file filter if a period is leading
113 If StringLeft($aFilterSplit[$iCC], 1) == "." Then $aFilterSplit[$iCC] = "*" & $aFilterSplit[$iCC] ;, "**", "*")
114
115 ;Replace multiple asterisks in file filter
116 $sFilter = StringReplace("*" & $sFilter & "*", "**", "*")
117 Select; options for not recursing; quicker than filtering after for single directory
118
119 ;Below needs work, _FileListToArrayBrief1 and _FileListToArrayBrief2 should be consolidated with an option passed for the files / folders flag
120
121 ;Fastest, with files ONLY, not recursed
122 Case Not $iRecurse And Not $iFlag And Not $iBaseDir
123 _FileListToArrayBrief2($arFolders[$iCF], $sFileString, $aFilterSplit[$iCC], $sExclude)
124
125 ;Not $iRecurse and And $iBaseDir ;fast, with files and folders, not recursed
126 Case Not $iFlag
127 _FileListToArrayBrief1($arFolders[$iCF], $sFileString, $aFilterSplit[$iCC], $sExclude)
128
129 ;Fast, with files only, not recursed
130 Case $iFlag = 1
131 _FileListToArrayFiles($arFolders[$iCF], $sFileString, $aFilterSplit[$iCC], $sExclude)
132
133 ;Folders only , not recursed
134 Case Not $iRecurse And $iFlag = 2
135 _FileListToArrayFolders($arFolders[$iCF], $sFileString, $aFilterSplit[$iCC], $iRecurse, $sExclude)
136 EndSelect;$cw = ConsoleWrite("$iCC=" & $iCC & " $sFileString =" & @LF & $sFileString & @LF)
137
138 ;Append pipe symbol and current file filter onto $sHoldSplit ???????
139 If $iCF = 0 Then $sHoldSplit &= '|' & $aFilterSplit[$iCC]; $cw = ConsoleWrite("$iCC=" & $iCC & " $sFileString =" & @LF & $sFileString & @LF)
140 Next
141
142 ;Replace multiple asterisks
143 If $iCF = 0 Then $sFilter = StringReplace(StringTrimLeft($sHoldSplit, 1), "**", "*");,$cw = ConsoleWrite("$iCC=" & $iCC & " $sFilter =" & @LF & $sFilter & @LF)
144 Next
145 EndIf
146;~ EndIf
147
148 ;Below needs work....
149
150 ;If recursive, folders-only, and filter ins't a wildcard
151 If $iRecurse And ($iFlag = 2) And StringTrimRight($sFilter, 1) <> "*" And StringTrimRight($sFilter, 1) <> "*.*" And Not StringInStr($sFilter, "**") Then ; filter folders -------------------
152
153 ;Trim trailing character
154 $sFileString1 = StringTrimRight(StringReplace($sFileString1, "*", @LF), 1)
155
156 ;Change the filters to RegExp filters
157 $sFilter1 = StringReplace(StringReplace(StringReplace($sFilter1, ".", "\."), "*", ".*"), "?", ".")
158 Local $pattern = '(?m)(^(?i)' & $sFilter1 & '$)' ;, $cw = ConsoleWrite("$sFilter =" & @LF & $sFilter1 & @LF), $cw = ConsoleWrite("$pattern =" & @LF & $pattern & @LF)
159 Local $asList = StringRegExp($sFileString1, $pattern, 3)
160;~ _ArrayDisplay($asList)
161 ;If only relative file / folder names are desired
162 If (Not $iBaseDir) Then
163
164 ;ARRAY.AU3 DEPENDENCY
165 $sFileString1 = _ArrayToString($asList, "*")
166 $sFileString1 = StringReplace($sFileString1, $sPath & "\", "", 0, 2)
167 $asList = StringSplit($sFileString1, "*")
168 EndIf
169 ElseIf $iRecurse And ($iFlag = 2) Then
170 $sFileString = StringStripCR($sFileString1)
171 EndIf;If UBound($asList) > 1 Then ConsoleWrite("$asList[1] =" & @LF & $asList[1] & @LF);~
172;~ _ArrayDisplay($asList)
173
174 ;ARRAY.AU3 DEPENDENCY
175 If IsArray($asList) And UBound($asList) > 0 And $asList[0] <> "" And Not IsNumber($asList[0]) Then _ArrayInsert($asList, 0, UBound($asList))
176 If IsArray($asList) And UBound($asList) > 1 And $asList[0] <> "" Then Return $asList
177 If (Not $iBaseDir) Or (Not $iRecurse And Not $iFlag And Not $iBaseDir) Then $sFileString = StringReplace($sFileString, $sPath & "\", "", 0, 2)
178 $arReturn = StringSplit(StringTrimRight($sFileString, 1), "*");~ local $a=ConsoleWrite("$sFileString :"&@lf&StringReplace($sFileString,"|",@crlf)&@lf),$timerstamp1=TimerInit()
179 If $i_deleteduplicate And IsArray($arReturn) And UBound($arReturn) > 1 And $arReturn[1] <> "" And Not (UBound($aFilterSplit) = 3 And $aFilterSplit[2] == "") Then _ArrayDeleteDupes($arReturn);and $arFolders[1]<>""
180 Return $arReturn;~ Return StringSplit(StringTrimRight($sFileString, 1), "*")
181EndFunc ;==>_FileListToArray3
182;===============================================================================
183;
184; Description: _ArrayDeleteDupes; deletes duplicates in an Array 1D
185; Syntax: _ArrayDeleteDupes(ByRef $ar_Array)
186; Parameter(s): $ar_Array = 1d Array
187; Requirement(s): None
188; Return Value(s): On Success - Returns asorted array with no duplicates
189; On Failure -
190; @Error=1 P
191; @Error=2
192;
193; Author(s): randallc
194;===============================================================================
195Func _ArrayDeleteDupes(ByRef $arrItems)
196 If @OSTYPE = "WIN32_WINDOWS" Then Return 0
197 Local $i = 0, $objDictionary = ObjCreate("Scripting.Dictionary")
198 For $strItem In $arrItems
199 If Not $objDictionary.Exists($strItem) Then
200 $objDictionary.Add($strItem, $strItem)
201 EndIf
202 Next
203 ReDim $arrItems[$objDictionary.Count ]
204 For $strKey In $objDictionary.Keys
205 $arrItems[$i] = $strKey
206 $i += 1
207 Next
208 $arrItems[0 ] = $objDictionary.Count - 1
209 Return 1
210EndFunc ;==>_ArrayDeleteDupes
211;===============================================================================
212;
213; Description: Helper self-calling func for _FileListToArray wrapper; lists all folders in a specified path
214; Syntax: _FileListToArrayFolders($s_PathF, ByRef $s_FileStringF, $s_FilterF, $i_RecurseF)
215; Parameter(s): $s_PathF = Path to generate filelist for
216; $s_FileStringF = The string for lists all folders only in a specified path
217; $s_FilterF = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
218; $i_RecurseF = Indicate whether recursion to subfolders required
219; $i_RecurseF=0(Default) No recursion to subfolders
220; $i_RecurseF=1 recursion to subfolders
221; $sExcludeF= The Exclude filter to use. "WildCards" For details
222; Requirement(s): None
223; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
224; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
225; @Error=1 Path not found or invalid
226; @Error=2 Invalid $s_Filter
227; @Error=3 Invalid $i_Flag
228; @Error=4 No File(s) Found
229;
230; Author(s): randallc; modified from SolidSnake, SmoKe_N, GEOsoft and big_daddy
231;===============================================================================
232Func _FileListToArrayFolders($sPathF, ByRef $sFileStringF, $sFilterF, $iRecurseF, $sExcludeF = "")
233 Local $hSearch = FileFindFirstFile($sPathF & "\" & $sFilterF), $sPathF2
234 If $hSearch = -1 Then Return SetError(4, 4, "")
235 If $sExcludeF == "" Then
236 While 1
237 $sFileF = FileFindNextFile($hSearch)
238 If @error Then
239 SetError(0)
240 ExitLoop
241 EndIf
242 $sPathF2 = $sPathF & "\" & $sFileF
243 If StringInStr(FileGetAttrib($sPathF2), "D") Then ;directories only wanted; and the attrib shows is directory
244 $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
245 If $iRecurseF = 1 Then _FileListToArrayFolders($sPathF2, $sFileStringF, $sFilterF, $iRecurseF)
246 EndIf
247 WEnd
248 Else
249 While 1
250 $sFileF = FileFindNextFile($hSearch)
251 If @error Then
252 SetError(0)
253 ExitLoop
254 EndIf
255 $sPathF2 = $sPathF & "\" & $sFileF; if folders only and this pattern matches exclude pattern, no further list or subdir
256 If StringRegExp($sPathF2, $sExcludeF) Then ContinueLoop
257 If StringInStr(FileGetAttrib($sPathF2), "D") Then ;directories only wanted; and the attrib shows is directory
258 $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter with * as delimiter
259 If $iRecurseF = 1 Then _FileListToArrayFolders($sPathF2, $sFileStringF, $sFilterF, $iRecurseF, $sExcludeF)
260 EndIf
261 WEnd
262 EndIf
263 FileClose($hSearch)
264EndFunc ;==>_FileListToArrayFolders
265;===============================================================================
266;
267; Description: Helper func for _FileListToArray wrapper; lists all files in a specified path
268; Syntax: _FileListToArrayFiles($s_PathF, ByRef $s_FileStringF, $s_FilterF) ;quick as not recursive
269; Parameter(s): $s_PathF = Path to generate filelist for
270; $s_FileStringF = The string for lists all files and folders in a specified path
271; $s_FilterF = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
272; $sExcludeF= The Exclude filter to use. "WildCards" For details
273; Requirement(s): None
274; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
275; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
276; @Error=1 Path not found or invalid
277; @Error=2 Invalid $s_Filter
278; @Error=4 No File(s) Found
279;
280; Author(s): randallc; modified from SolidSnake, SmoKe_N, GEOsoft and big_daddy
281;===============================================================================
282Func _FileListToArrayFiles($sPathF, ByRef $sFileStringF, $sFilterF, $sExcludeF = "")
283 Local $hSearch = FileFindFirstFile($sPathF & "\" & $sFilterF), $sPathF2
284 If $hSearch = -1 Then Return SetError(4, 4, "")
285 If $sExcludeF == "" Then
286 While 1
287 $sFileF = FileFindNextFile($hSearch)
288 If @error Then
289 SetError(0)
290 ExitLoop
291 EndIf
292 $sPathF2 = $sPathF & "\" & $sFileF;directories not wanted; and the attrib shows not directory
293 If Not StringInStr(FileGetAttrib($sPathF2), "D") Then $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
294 WEnd
295 Else
296 While 1
297 $sFileF = FileFindNextFile($hSearch)
298 If @error Then
299 SetError(0)
300 ExitLoop
301 EndIf
302 $sPathF2 = $sPathF & "\" & $sFileF;directories not wanted; and the attrib shows not directory; and filename [only] does not match exclude
303 If Not StringInStr(FileGetAttrib($sPathF2), "D") _
304 And Not StringRegExp($sFileF, $sExcludeF) Then $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
305 WEnd
306 EndIf
307 FileClose($hSearch)
308EndFunc ;==>_FileListToArrayFiles
309;===============================================================================
310;
311; Description: Helper self-calling func for _FileListToArray wrapper; lists all files and folders in a specified path, recursive
312; Syntax: _FileListToArrayRecFiles($s_PathF, ByRef $s_FileStringF, $s_FilterF) ; recursive
313; Parameter(s): $s_PathF = Path to generate filelist for
314; $s_FileStringF = The string for lists all files and folders in a specified path
315; $s_FilterF = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
316; $sExcludeF= The Exclude filter to use. "WildCards" For details
317; Requirement(s): None
318; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
319; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
320; @Error=1 Path not found or invalid
321; @Error=2 Invalid $s_Filter
322; @Error=4 No File(s) Found
323;
324; Author(s): randallc; modified from SolidSnake, SmoKe_N, GEOsoft and big_daddy
325;===============================================================================
326Func _FileListToArrayRecAll($sPathF, ByRef $sFileStringF, $sFilterF, $sExcludeF = "")
327 Local $hSearch = FileFindFirstFile($sPathF & "\" & $sFilterF), $sPathF2
328 If $hSearch = -1 Then Return SetError(4, 4, "")
329 If $sExcludeF == "" Then
330 While 1
331 $sFileF = FileFindNextFile($hSearch)
332 If @error Then
333 SetError(0)
334 ExitLoop
335 EndIf
336 $sPathF2 = $sPathF & "\" & $sFileF
337 $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
338 If StringInStr(FileGetAttrib($sPathF2), "D") Then _FileListToArrayRecAll($sPathF2, $sFileStringF, $sFilterF);, $iFlagF, $iRecurseF)
339 WEnd
340 Else
341 While 1
342 $sFileF = FileFindNextFile($hSearch)
343 If @error Then
344 SetError(0)
345 ExitLoop
346 EndIf
347 $sPathF2 = $sPathF & "\" & $sFileF
348 If StringInStr(FileGetAttrib($sPathF2), "D") Then
349 $sFileStringF &= $sPathF2 & "*" ;this writes the directoryname
350 _FileListToArrayRecAll($sPathF2, $sFileStringF, $sFilterF, $sExcludeF);, $iFlagF, $iRecurseF)
351 Else ;if not directory, check Exclude match
352 If Not StringRegExp($sFileF, $sExcludeF) Then $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
353 EndIf
354 WEnd
355 EndIf
356 FileClose($hSearch)
357EndFunc ;==>_FileListToArrayRecAll
358;===============================================================================
359;
360; Description: Helper self-calling func for _FileListToArray wrapper; lists all files in a specified path, recursive
361; Syntax: _FileListToArrayRecFiles($s_PathF, ByRef $s_FileStringF, $s_FilterF) ; recursive
362; Parameter(s): $s_PathF = Path to generate filelist for
363; $s_FileStringF = The string for lists all files and folders in a specified path
364; $s_FilterF = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
365; $sExcludeF= The Exclude filter to use. "WildCards" For details
366; Requirement(s): None
367; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
368; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
369; @Error=1 Path not found or invalid
370; @Error=2 Invalid $s_Filter
371; @Error=4 No File(s) Found
372;
373; Author(s): randallc; modified from SolidSnake, SmoKe_N, GEOsoft and big_daddy
374;===============================================================================
375Func _FileListToArrayRecFiles($sPathF, ByRef $sFileStringF, $sFilterF, $sExcludeF = "")
376 Local $hSearch = FileFindFirstFile($sPathF & "\" & $sFilterF), $sPathF2
377 If $hSearch = -1 Then Return SetError(4, 4, "")
378 If $sExcludeF == "" Then
379 While 1
380 $sFileF = FileFindNextFile($hSearch)
381 If @error Then
382 SetError(0)
383 ExitLoop
384 EndIf
385 $sPathF2 = $sPathF & "\" & $sFileF
386 If StringInStr(FileGetAttrib($sPathF2), "D") Then
387 _FileListToArrayRecFiles($sPathF2, $sFileStringF, $sFilterF);, $iFlagF, $iRecurseF)
388 Else
389 $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
390 EndIf
391 WEnd
392 Else
393 While 1
394 $sFileF = FileFindNextFile($hSearch)
395 If @error Then
396 SetError(0)
397 ExitLoop
398 EndIf
399 $sPathF2 = $sPathF & "\" & $sFileF
400 If StringInStr(FileGetAttrib($sPathF2), "D") Then
401 _FileListToArrayRecFiles($sPathF2, $sFileStringF, $sFilterF, $sExcludeF);, $iFlagF, $iRecurseF)
402 Else
403 If Not StringRegExp($sFileF, $sExcludeF) Then $sFileStringF &= $sPathF2 & "*" ;this writes the filename to the delimited string with * as delimiter
404 EndIf
405 WEnd
406 EndIf
407 FileClose($hSearch)
408EndFunc ;==>_FileListToArrayRecFiles
409;===============================================================================
410;
411; Description: Helper func for _FileListToArray wrapper; lists all files ONLY in a specified path, not recursive
412; Syntax: _FileListToArrayBrief2($s_PathF, ByRef $s_FileStringF, $s_FilterF) ;quick as not recursive
413; Parameter(s): $s_PathF = Path to generate filelist for
414; $s_FileStringF = The string for lists all files and folders in a specified path
415; $s_FilterF = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
416; $sExcludeF= The Exclude filter to use. "WildCards" For details
417; Requirement(s): None
418; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
419; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
420; @Error=1 Path not found or invalid
421; @Error=2 Invalid $s_Filter
422; @Error=4 No File(s) Found
423;
424; Author(s): randallc; modified from SolidSnake, SmoKe_N, GEOsoft and big_daddy
425;===============================================================================
426Func _FileListToArrayBrief2($sPathF, ByRef $sFileStringF, $sFilterF, $sExcludeF = "")
427 $hSearch = FileFindFirstFile($sPathF & "\" & $sFilterF)
428 If $hSearch = -1 Then Return SetError(4, 4, "")
429 If $sExcludeF == "" Then
430 While 1
431 $sFileF = FileFindNextFile($hSearch)
432 If @error Then
433 SetError(0)
434 ExitLoop
435 EndIf
436 $sFileStringF &= $sFileF & "*" ;this writes the filename to the delimited string with * as delimiter; only time no full path included
437 WEnd
438 Else
439 While 1
440 $sFileF = FileFindNextFile($hSearch)
441 If @error Then
442 SetError(0)
443 ExitLoop
444 EndIf ;If not StringRegExp($sFileF,$sExcludeF) then $sFileStringF &= $sPathF2 & "*"
445 If Not StringRegExp($sFileF, $sExcludeF) Then $sFileStringF &= $sFileF & "*" ;this writes the filename to the delimited string with * as delimiter; only time no full path included
446 WEnd
447 EndIf
448 FileClose($hSearch)
449EndFunc ;==>_FileListToArrayBrief2
450;===============================================================================
451;
452; Description: Helper func for _FileListToArray wrapper; lists all files and folders in a specified path, not recursive
453; Syntax: _FileListToArrayBrief1($s_PathF, ByRef $s_FileStringF, $s_FilterF) ;quick as not recursive
454; Parameter(s): $s_PathF = Path to generate filelist for
455; $s_FileStringF = The string for lists all files and folders in a specified path
456; $s_FilterF = The filter to use. Search the Autoit3 manual for the word "WildCards" For details
457; $sExcludeF= The Exclude filter to use. "WildCards" For details
458; Requirement(s): None
459; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
460; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
461; @Error=1 Path not found or invalid
462; @Error=2 Invalid $s_Filter
463; @Error=4 No File(s) Found
464;
465; Author(s): randallc; modified from SolidSnake, SmoKe_N, GEOsoft and big_daddy
466;===============================================================================
467Func _FileListToArrayBrief1($sPathF, ByRef $sFileStringF, $sFilterF, $sExcludeF = "")
468 $hSearch = FileFindFirstFile($sPathF & "\" & $sFilterF)
469 If $hSearch = -1 Then Return SetError(4, 4, "")
470 If $sExcludeF == "" Then
471 While 1
472 $sFileF = FileFindNextFile($hSearch)
473 If @error Then
474 SetError(0)
475 ExitLoop
476 EndIf
477 $sFileStringF &= $sPathF & "\" & $sFileF & "*" ;this writes the filename to the delimited string with * as delimiter [remo]
478 WEnd
479 Else
480 While 1
481 $sFileF = FileFindNextFile($hSearch)
482 If @error Then
483 SetError(0)
484 ExitLoop
485 EndIf
486 If Not StringRegExp($sFileF, $sExcludeF) Then $sFileStringF &= $sPathF & "\" & $sFileF & "*" ;this writes the filename to the delimited string with * as delimiter [remo]
487 WEnd
488 EndIf
489 FileClose($hSearch)
490EndFunc ;==>_FileListToArrayBrief1