Jump to content

BaKaMu

Active Members
  • Posts

    75
  • Joined

  • Last visited

BaKaMu's Achievements

Wayfarer

Wayfarer (2/7)

0

Reputation

  1. @Tiem Good news, Problem is solved! It was my fault, FileClose is the magic function. (you have been on the right track) So nothing is wrong with FileExists, FileFindFirstFile, FileFindNextFile or DirRemove. (I should always read the help-section to the end !!! mea culpa) A quick and dirty solution: I have consequently added FileClose, so _FileListToArrayXT seems to work right now (i hope so). Please test the function and give feedback. I do apologize about the bug in _FileListToArrayXT. BaKaMu ; #FUNCTION# =========================================================================================== ; Name: _FileListToArrayXT ; Description: Lists files and\or folders in specified path(s) (Similar to using Dir with the /B Switch) ; additional features: multi-path, multi-filter, multi-exclude-filter, path format options, recursive search ; Corrected on 2010/08/19: Added FileClose() ; Syntax: _FileListToArrayXT([$sPath = @ScriptDir, [$sFilter = "*", [$iRetItemType, [$bRecursive = False, [$sExclude = "", [$iRetFormat = 1]]]]]]) ; Parameter(s): $sPath = optional: Search path(s), semicolon delimited (default: @ScriptDir) ; (Example: "C:\Tmp;D:\Temp") ; $sFilter = optional: Search filter(s), semicolon delimited . Wildcards allowed. (default: "*") ; (Example: "*.exe;*.txt") ; $iRetItemType = Include in search: 0 = Files and Folder, 1 = Files Only, 2 = Folders Only ; $iRetPathType = Returned element format: 0 = file/folder name only, 1 = relative path, 2 = full path ; $bRecursive = optional: True: recursive search including all subdirectories ; False (default): search only in specified folder ; $sExclude = optional: Exclude filter(s), semicolon delimited. Wildcards allowed. ; (Example: "Unins*" will remove all files/folders that begin with "Unins") ; $iRetFormat = optional: return format ; 0 = one-dimensional array, 0-based ; 1 = one-dimensional array, 1-based (default) ; 2 = String ( "|" delimited) ; Requirement(s): AutoIt Version 3.3.1.1 or newer ; Return Value(s): on success: 1-based or 0-based array or string (dependent on $iRetFormat) ; If no path is found, @error and @extended are set to 1, returns empty string ; If no filter is found, @error and @extended are set to 2, returns empty string ; If $iRetFormat is invalid, @error and @extended are set to 3, returns empty string ; If no data is found, @error and @extended are set to 4, returns empty string ; Author(s): Half the AutoIt Community ; ==================================================================================================== Func _FileListToArrayXT($sPath = @ScriptDir, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False, $sExclude = "", $iRetFormat = 1) Local $hSearchFile, $sFile, $sFileList, $sWorkPath, $sRetPath, $iRootPathLen, $iPCount, $iFCount, $fDirFlag ;[check and prepare parameters] ;--------------- If $sPath = -1 Or $sPath = Default Then $sPath = @ScriptDir ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sPath = StringRegExpReplace(StringRegExpReplace($sPath, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check that at least one path is set If $sPath = "" Then Return SetError(1, 1, "") ;----- If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*" ;prepare filter ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sFilter = StringRegExpReplace(StringRegExpReplace($sFilter, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check for invalid chars or that at least one filter is set If StringRegExp($sFilter, "[\\/><:\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "") If $bRecursive Then ;Convert $sFilter for Regular Expression $sFilter = StringRegExpReplace($sFilter, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sFilter = StringReplace($sFilter, "?", ".") $sFilter = StringReplace($sFilter, "*", ".*?") $sFilter = "(?i)\A(" & StringReplace($sFilter, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings ;$sFilter = "(?i)\A" & StringReplace($sFilter, ";", "|") & "\z" EndIf ;----- If $iRetItemType <> "1" And $iRetItemType <> "2" Then $iRetItemType = "0" ;----- If $iRetPathType <> "1" And $iRetPathType <> "2" Then $iRetPathType = "0" ;----- $bRecursive = ($bRecursive = "1") ;----- If $sExclude = -1 Or $sExclude = Default Then $sExclude = "" If $sExclude Then ;prepare $sExclude ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;Convert $sExclude for Regular Expression $sExclude = StringRegExpReplace($sExclude, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sExclude = StringReplace($sExclude, "?", ".") $sExclude = StringReplace($sExclude, "*", ".*?") $sExclude = "(?i)\A(" & StringReplace($sExclude, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings ;$sExclude = "(?i)\A" & StringReplace($sExclude, ";", "|") & "\z" EndIf ;----- ;If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1" If Not ($iRetItemType = 0 Or $iRetItemType = 1 Or $iRetItemType = 2) Then Return SetError(3, 3, "") ;--------------- ;[/check and prepare parameters] ;--------------- Local $aPath = StringSplit($sPath, ';', 1) ;paths array Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array ;--------------- If $bRecursive Then ;different handling for recursion (strategy: unfiltered search for all items and filter unwanted) If $sExclude Then ;different handling dependent on $sExclude parameter is set or not For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop $iRootPathLen = StringLen($sPath) - 1 Local $aPathStack[1024] = [1, $sPath] While $aPathStack[0] > 0 $sWorkPath = $aPathStack[$aPathStack[0]] $aPathStack[0] -= 1 ;----- $hSearchFile = FileFindFirstFile($sWorkPath & '*') If @error Then FileClose($hSearchFile) ContinueLoop EndIf ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sWorkPath Case 1 ;relative path $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1) EndSwitch ;----- Switch $iRetItemType Case 1 While True ;Files only $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf $fDirFlag = @extended If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" ContinueLoop EndIf If StringRegExp($sFile, $sExclude) Then ContinueLoop If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case 2 While True ;Folders only $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf $fDirFlag = @extended If StringRegExp($sFile, $sExclude) Then ContinueLoop If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case Else While True ;Files and Folders $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf $fDirFlag = @extended If StringRegExp($sFile, $sExclude) Then ContinueLoop If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" EndIf If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd EndSwitch ;----- WEnd FileClose($hSearchFile) Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop $iRootPathLen = StringLen($sPath) - 1 Local $aPathStack[1024] = [1, $sPath] While $aPathStack[0] > 0 $sWorkPath = $aPathStack[$aPathStack[0]] $aPathStack[0] -= 1 ;----- $hSearchFile = FileFindFirstFile($sWorkPath & '*') If @error Then FileClose($hSearchFile) ContinueLoop EndIf ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sWorkPath Case 1 ;relative path $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1) EndSwitch ;----- Switch $iRetItemType Case 1 While True ;Files only $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" ContinueLoop EndIf If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case 2 While True ;Folders only $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case Else While True ;Files and Folders $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" EndIf If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd EndSwitch ;----- WEnd FileClose($hSearchFile) Next ;$iPCount - next path EndIf ;If $sExclude Else ;If Not $bRecursive (strategy: filtered search for items) If $sExclude Then ;different handling dependent on $sExclude parameter is set or not For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sPath Case 1 ;relative path $sRetPath = "" EndSwitch For $iFCount = 1 To $aFilter[0] ;filter loop ;----- $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount]) If @error Then FileClose($hSearchFile) ContinueLoop EndIf ;----- Switch $iRetItemType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then ContinueLoop ;bypass folder ;check for exclude files If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sRetPath & $sFile & "|" WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then ;bypass file ;check for exclude folder If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf ;check for exclude files/folder If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sRetPath & $sFile & "|" WEnd EndSwitch FileClose($hSearchFile) Next ;$iFCount - next filter Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sPath Case 1 ;relative path $sRetPath = "" EndSwitch For $iFCount = 1 To $aFilter[0] ;filter loop ;----- $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount]) If @error Then FileClose($hSearchFile) ContinueLoop EndIf ;----- Switch $iRetItemType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then ContinueLoop ;bypass folder $sFileList &= $sRetPath & $sFile & "|" WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf If @extended Then ;bypass file $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearchFile) If @error Then FileClose($hSearchFile) ExitLoop EndIf $sFileList &= $sRetPath & $sFile & "|" WEnd EndSwitch FileClose($hSearchFile) Next ;$iFCount - next filter Next ;$iPCount - next path EndIf ;If $sExclude EndIf ;If $bRecursive ;--------------- ;set according return value If $sFileList Then Switch $iRetFormat Case 2 ;return a delimited string Return StringTrimRight($sFileList, 1) Case 0 ;return a 0-based array Return StringSplit(StringTrimRight($sFileList, 1), "|", 2) Case Else ;return a 1-based array Return StringSplit(StringTrimRight($sFileList, 1), "|", 1) EndSwitch Else Return SetError(4, 4, "") EndIf EndFunc ;==>_FileListToArrayXT
  2. @Tiem unfortunately my tests have confirmed this behavior, but at the moment i have no idea why. The result of _FileListToArrayXT is correct, but it seems, that the dir is locked. _FileListToArrayXT only uses three file-operations: FileExists, FileFindFirstFile and FileFindNextFile. All of these are normal internal autoit functions and besides there is nothing special in _FileListToArrayXT. Maybe one of this functions is problematical (does not release file-handle or something else). Maybe DirRemove is problematical. Because these are internal AutoIt functions, i can not go deeper in source. But it is good to know, that there is a problem. Thank you for reporting this behavior, i will observe this further on. bakamu
  3. Based on some new suggestions, I have developed a following version of _FileListToArrayNT7 --> _FileListToArrayXT Some preliminary remarks: This version is designed for AutoIt Version 3.3.1.1 or newer. Otherwise you have to change all --> @extended <-- back to --> StringInStr(FileGetAttrib($sPath & $sFile), "D") <> 0 <-- (not tested) In no circumstances a recommendation will be made to include it in a general UDF. ;-) So use it or not , it is your decision. According to a suggestion from Spiff59 I have changed the search strategy in some cases: old _FileListToArrayNT7 (post #175): filtered search for each filter (strategy 1). If recursion (search in subdirs) is necessary then additional unfiltered searches for subdirs are done. new _FileListToArrayXT: if no recursion: search like _FileListToArrayNT7 (strategy 1). if recursion: do an unfiltered search for all items and filter out unwanted items (strategy 2). To my surprise, this combination of search strategies gives an impressive speed improvement (up to 100%), especially if more than on filter is used (ex: "*.avi;*,mpg;*.flv;*.mov") There are also two branches of code in each case of recursion (if excluding is set or not) for speed improvement. (and due to the new pseudo-recursion the unpractical "do not use" parameter $sWorkPath could be removed) This results in noticeable more code lines (please don't flame therefore), but the operating profit is again a really good speed improvement (compared to the already fast _FileListToArrayNT7) in most of the cases. The functionality is still the same as in _FileListToArrayNT7 (multi-path, multi-filter, recursion, exclude and so on) Two small changes: Excluding now depends on $iRetItemType: If files only, excluding is only done for file names, otherwise also for folder names. Search for "*.dat" returns only *.dat files (so no *.data will be returned as in the case of dir command) Example: Search for all video files on disk C: and D: , but no videos with "demo" or "test" in filename: $aRetArray = _FileListToArrayXT("C:\;D:\", "*.avi;*.mpg;*.mpeg;*.mp4;*.mkv;*.flv;*.ogg;*.ogm;*.mov", 1, 2, True, "*demo*;*test*") The first run is as usual somewhat slower (filling cache), but the next runs will be very fast (reading from cache). Some test results (all done out of cache): Test1: path: System32-Dir, filter="*.dll", return files/folders, full path, no recursion, no exclusion, repeats 300 _FileListToArray: Sec = 7.70 , 1832 items _FileListToArrayNT7: Sec = 4.61 , 1832 items _FileListToArrayXT: Sec = 4.62 , 1832 items Test2: path: System32-Dir, filter="*", return files/folders, full path, no recursion, no exclusion, repeats 300 _FileListToArray: Sec = 12.80 , 3114 items _FileListToArrayNT7: Sec = 7.30 , 3114 items _FileListToArrayXT: Sec = 7.31 , 3114 items Test3: path: System32-Dir, filter="*nothing*.xyz", return files/folders, full path, no recursion, no exclusion, repeats 300 _FileListToArray: Sec = 0.53 , 0 items _FileListToArrayNT7: Sec = 0.56 , 0 items _FileListToArrayXT: Sec = 0.56 , 0 items Test4: path: System32-Dir, filter="*.dll", return files/folders, full path, recursion, no exclusion, repeats 50 _FileListToArrayNT7: Sec = 7.52 , 2895 items _FileListToArrayXT: Sec = 6.44 , 2895 items Test5: path: System32-Dir, filter="*.dll;*.exe", return files/folders, full path, recursion, no exclusion, repeats 50 _FileListToArrayNT7: Sec = 9.14 , 3555 items _FileListToArrayXT: Sec = 7.03 , 3555 items Test6: path: System32-Dir, filter="*.dll;*.exe;*.sys;*.log", return files/folders, full path, recursion, no exclusion, repeats 50 _FileListToArrayNT7: Sec = 12.06 , 4180 items _FileListToArrayXT: Sec = 7.88 , 4180 items Test7: path: System32-Dir, filter="*", return files/folders, full path, recursion, exclusion: "*.dll;*.exe", repeats 50 _FileListToArrayNT7: Sec = 12.08 , 3669 items _FileListToArrayXT: Sec = 8.16 , 3669 items Test8: path: HDD C:, filter="*.avi;*.mpg;*.mpeg;*.mp4;*.mkv;*.flv;*.ogg;*.ogm;*.mov", return files, full path, recursion, exclusion: "*Demo*.exe", repeats 1 _FileListToArrayNT7: Sec = 16.16 , 116 items _FileListToArrayXT: Sec = 8.72 , 116 items Test9: path: Test-Dir (13608 files, 1092 folders), 6 filters, return files, full path, recursion, 1 exclusion, repeats 30 _FileListToArrayNT7: Sec = 36.94 , 10750 items _FileListToArrayXT: Sec = 17.05 , 10750 items As you can see, the performance isn't bad at all. Please make your own tests to check stability and functionality and report if you find a bug. _FileListToArrayXT (For Spiff59: _FileListToArraySuperTurbo5000ExtraPlusProWithMaximumUltraPowerboost) ; #FUNCTION# =========================================================================================== ; Name: _FileListToArrayXT ; Description: Lists files and\or folders in specified path(s) (Similar to using Dir with the /B Switch) ; additional features: multi-path, multi-filter, multi-exclude-filter, path format options, recursive search ; Syntax: _FileListToArrayXT([$sPath = @ScriptDir, [$sFilter = "*", [$iRetItemType, [$bRecursive = False, [$sExclude = "", [$iRetFormat = 1]]]]]]) ; Parameter(s): $sPath = optional: Search path(s), semicolon delimited (default: @ScriptDir) ; (Example: "C:\Tmp;D:\Temp") ; $sFilter = optional: Search filter(s), semicolon delimited . Wildcards allowed. (default: "*") ; (Example: "*.exe;*.txt") ; $iRetItemType = Include in search: 0 = Files and Folder, 1 = Files Only, 2 = Folders Only ; $iRetPathType = Returned element format: 0 = file/folder name only, 1 = relative path, 2 = full path ; $bRecursive = optional: True: recursive search including all subdirectories ; False (default): search only in specified folder ; $sExclude = optional: Exclude filter(s), semicolon delimited. Wildcards allowed. ; (Example: "Unins*" will remove all files/folders that begin with "Unins") ; $iRetFormat = optional: return format ; 0 = one-dimensional array, 0-based ; 1 = one-dimensional array, 1-based (default) ; 2 = String ( "|" delimited) ; Requirement(s): AutoIt Version 3.3.1.1 or newer ; Return Value(s): on success: 1-based or 0-based array or string (dependent on $iRetFormat) ; If no path is found, @error and @extended are set to 1, returns empty string ; If no filter is found, @error and @extended are set to 2, returns empty string ; If $iRetFormat is invalid, @error and @extended are set to 3, returns empty string ; If no data is found, @error and @extended are set to 4, returns empty string ; Author(s): Half the AutoIt Community ; ==================================================================================================== Func _FileListToArrayXT($sPath = @ScriptDir, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False, $sExclude = "", $iRetFormat = 1) Local $hSearchFile, $sFile, $sFileList, $sWorkPath, $sRetPath, $iRootPathLen, $iPCount, $iFCount, $fDirFlag ;[check and prepare parameters] ;--------------- If $sPath = -1 Or $sPath = Default Then $sPath = @ScriptDir ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sPath = StringRegExpReplace(StringRegExpReplace($sPath, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check that at least one path is set If $sPath = "" Then Return SetError(1, 1, "") ;----- If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*" ;prepare filter ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sFilter = StringRegExpReplace(StringRegExpReplace($sFilter, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check for invalid chars or that at least one filter is set If StringRegExp($sFilter, "[\\/><:\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "") If $bRecursive Then ;Convert $sFilter for Regular Expression $sFilter = StringRegExpReplace($sFilter, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sFilter = StringReplace($sFilter, "?", ".") $sFilter = StringReplace($sFilter, "*", ".*?") $sFilter = "(?i)\A(" & StringReplace($sFilter, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings ;$sFilter = "(?i)\A" & StringReplace($sFilter, ";", "|") & "\z" EndIf ;----- If $iRetItemType <> "1" And $iRetItemType <> "2" Then $iRetItemType = "0" ;----- If $iRetPathType <> "1" And $iRetPathType <> "2" Then $iRetPathType = "0" ;----- $bRecursive = ($bRecursive = "1") ;----- If $sExclude = -1 Or $sExclude = Default Then $sExclude = "" If $sExclude Then ;prepare $sExclude ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;Convert $sExclude for Regular Expression $sExclude = StringRegExpReplace($sExclude, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sExclude = StringReplace($sExclude, "?", ".") $sExclude = StringReplace($sExclude, "*", ".*?") $sExclude = "(?i)\A(" & StringReplace($sExclude, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings ;$sExclude = "(?i)\A" & StringReplace($sExclude, ";", "|") & "\z" EndIf ;----- ;If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1" If Not ($iRetItemType = 0 Or $iRetItemType = 1 Or $iRetItemType = 2) Then Return SetError(3, 3, "") ;--------------- ;[/check and prepare parameters] ;--------------- Local $aPath = StringSplit($sPath, ';', 1) ;paths array Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array ;--------------- If $bRecursive Then ;different handling for recursion (strategy: unfiltered search for all items and filter unwanted) If $sExclude Then ;different handling dependent on $sExclude parameter is set or not For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop $iRootPathLen = StringLen($sPath) - 1 Local $aPathStack[1024] = [1, $sPath] While $aPathStack[0] > 0 $sWorkPath = $aPathStack[$aPathStack[0]] $aPathStack[0] -= 1 ;----- $hSearchFile = FileFindFirstFile($sWorkPath & '*') If @error Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sWorkPath Case 1 ;relative path $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1) EndSwitch ;----- Switch $iRetItemType Case 1 While True ;Files only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $fDirFlag = @extended If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" ContinueLoop EndIf If StringRegExp($sFile, $sExclude) Then ContinueLoop If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case 2 While True ;Folders only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $fDirFlag = @extended If StringRegExp($sFile, $sExclude) Then ContinueLoop If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case Else While True ;Files and Folders $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $fDirFlag = @extended If StringRegExp($sFile, $sExclude) Then ContinueLoop If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" EndIf If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd EndSwitch ;----- WEnd FileClose($hSearchFile) Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop $iRootPathLen = StringLen($sPath) - 1 Local $aPathStack[1024] = [1, $sPath] While $aPathStack[0] > 0 $sWorkPath = $aPathStack[$aPathStack[0]] $aPathStack[0] -= 1 ;----- $hSearchFile = FileFindFirstFile($sWorkPath & '*') If @error Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sWorkPath Case 1 ;relative path $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1) EndSwitch ;----- Switch $iRetItemType Case 1 While True ;Files only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" ContinueLoop EndIf If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case 2 While True ;Folders only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case Else While True ;Files and Folders $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" EndIf If StringRegExp($sFile, $sFilter) Then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd EndSwitch ;----- WEnd FileClose($hSearchFile) Next ;$iPCount - next path EndIf ;If $sExclude Else ;If Not $bRecursive (strategy: filtered search for items) If $sExclude Then ;different handling dependent on $sExclude parameter is set or not For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sPath Case 1 ;relative path $sRetPath = "" EndSwitch For $iFCount = 1 To $aFilter[0] ;filter loop ;----- $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount]) If @error Then ContinueLoop ;----- Switch $iRetItemType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ContinueLoop ;bypass folder ;check for exclude files If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sRetPath & $sFile & "|" WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ;bypass file ;check for exclude folder If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop ;check for exclude files/folder If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sRetPath & $sFile & "|" WEnd EndSwitch FileClose($hSearchFile) Next ;$iFCount - next filter Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sPath Case 1 ;relative path $sRetPath = "" EndSwitch For $iFCount = 1 To $aFilter[0] ;filter loop ;----- $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount]) If @error Then ContinueLoop ;----- Switch $iRetItemType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ContinueLoop ;bypass folder $sFileList &= $sRetPath & $sFile & "|" WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ;bypass file $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $sFileList &= $sRetPath & $sFile & "|" WEnd EndSwitch FileClose($hSearchFile) Next ;$iFCount - next filter Next ;$iPCount - next path EndIf ;If $sExclude EndIf ;If $bRecursive ;--------------- ;set according return value If $sFileList Then Switch $iRetFormat Case 2 ;return a delimited string Return StringTrimRight($sFileList, 1) Case 0 ;return a 0-based array Return StringSplit(StringTrimRight($sFileList, 1), "|", 2) Case Else ;return a 1-based array Return StringSplit(StringTrimRight($sFileList, 1), "|", 1) EndSwitch Else Return SetError(4, 4, "") EndIf EndFunc ;==>_FileListToArrayXT
  4. Done (Post #175), i'm a little bit amused ;-)
  5. New approach after rollback ;-) What's wrong with that?Normally more function and sometimes more speed = more code (even AutoIt increases from version to version, and i don't see much more complexity in a 140 code line function) If you have a better function (with same functionality, stability and speed) with less code, i will be the first to use this function. Really! Don't agree (at least not in total), because in the logic of your statement, all the programming is open end forever.(so i have understood your words, but may be i am wrong). In practice there may be never a progamm that is 1000% bug-free and never fails in all imaginable and non imaginable circumstances. (and if this programm exists, no one wants to use it) :-) And in practice we normally finalize a programm if we are confident, that there is no more improvement. (there may be some more improvements, but we are confident that there are no more, please notice the difference) This is not a stupid approach, rather more practical. On the other hand i know, there are a lot of projects in real world which have been terminated and all participants knows that those are junk, but that's another question, we are discussing here about good programming. Anyway i digress to philosophic questions. It is my opinion that i am more on your side as you believe, nevertheless i'll think about your arguments further on.
  6. You may be surprised, that i agree with you. (not with your diction) But this doesn't care. With the helpful assistance of the community we have now a good replacement for _FileListToArray which is faster, more functional and returns the right results. So what we want more? Everyone can use it ore not, and it does not matter whether the function is in a general UDF or private UDF. It is more relevant, that this function now exists and is working good.
  7. Thank you very much for that (Merci beaucoup)
  8. Five stars for this statement. ;-) What we should do next. I have seen a post from jpm, from his point of view setting @extended = @error in case only @extended is tested is not a good reason. I agree with this statement also, especially it tends more in your direction, Really, i have no preference. I was directed from the facts of my speed tests. So i will edit _FileListToArrayNT7 (post #175) again and set all SetError(x, x, "") to SetError(x) (and correct the header) @jpm: should a final version be set in a new post now? And witch name should be set. Function header will now be ok (in a few minutes), who updates the help documentation (please not i). I'm glad that the work is done. Many thanks to all for the impelling suggestions, especially to spiff59 (his hardheadedness and practically thoughts was a very good motor for this project) So there is only a little tidy up remaining.
  9. If have now increased the number of my iterations from 30 to 300. And now, there is a little constantly speed improvement, contrary to 30 iterations. This is now the next question: Does SetError need a wake up call or a warm up phase. ;-) (I believe. that's are the mysteries of AutoIt, so i don't ask anymore) OK, sounds good, taken over. Edited post #175
  10. There is a point i can not understand:On my harddrive i have a testing structure of 10584 files, 1560 folders (different filenames/foldernames). This structure is related to the structure i have described in my first post in this thread. For testing i make always two tests (and this not only once) Test1: one path with 10584 files, 1560 folders, filter="*", return files/folders, full path, recursion, no exclusion, repeats 30 Test2: one path with 10584 files, 1560 folders, filter="*", return files/folders, full path, recursion, with one (folder) exclusion, repeats 30 so the test conditions are always the same (i even deactivated most of the background activities) The only difference between _FileListToArrayNT7 and _FileListToArrayNT8 is SetError(4, 4, "") and SetError(4) Your test routine shows constantly a faster speed for SetError(4) and my test results shows constantly a slower speed for _FileListToArrayNT8 with SetError(4) (i would understand if it's faster or even if it's equal, but not that it is slower, independent of the size of hard drives) That makes me crazy. What is the reason for this behavior? I want to understand the mechanism of this logic. It's against all the rules of programming, i have ever learned. Does it belong to my CPU or what else? I am perplexed. Hm, in the original _FileListToArray it isn't documented, so we also shouldn't do that.So this are goodies for insiders. ----------------------- I have done a lot of tests now, none of them has been incorrect. So maybe we have done the work now (just in time) :-) :-) Edit1: I was answering before i see your edits (especially edit2). I need some time for translation. ;-) Your arguments are acceptable as well.
  11. Yes, really interesting.I have done the error setting like --> SetError(1, 1, "") <-- for 100% backward compatibility to _FileListToArray. ex: _FileListToArray : If Not FileExists($sPath) Then Return SetError(1, 1, "") If this is not so important (in this special case), i am on board. Recommendation: we only change the SetError(4, 4, "") in the loop to SetError(4). So we have 100% backward compatibility and more speed. Has to been tested now ;-) Edit1: The test results are curious: Your test-routine shows a noticeable speed increase: t1 = 2.96 t2 = 1.63 In FLTA: SetError(4, 4, "") set to SetError(4) there is a speed decrease (nothing changed else): Test1: one path with 10584 files, 1560 folders, filter="*", return files/folders, full path, recursion, no exclusion, repeats 30 _FileListToArrayNT7: Sec = 15.89 , 12144 items _FileListToArrayNT8: Sec = 16.04 , 12144 items Test2: one path with 10584 files, 1560 folders, filter="*", return files/folders, full path, recursion, with one (folder) exclusion, repeats 30 _FileListToArrayNT7: Sec = 14.48 , 9719 items _FileListToArrayNT8: Sec = 14.55 , 9719 items I am just wondering whether this belongs to my machine only. Please test yourself Edit2: BTW: SetError(4...) is not called very often (even in recursion), cause error is only set if search result on folder is empty (= empty folder) Edit3: so i think we should stay at _FileListToArrayNT7, my tests doesn't show any instability until now.
  12. Done, edited post #175 The function name will be changed at last to whatever jpm wants. I will continue testing tomorrow.
  13. OK that's the last version of _FileListToArrayNT7 (better known as _FileListToArraySuperTurbo4000PlusProWithMaximumUltraPowerboost) Maybe the final version, so please check extensively ;-) (As usual, close to deadline there is a hectic atmosphere :-)) ; #FUNCTION# =========================================================================================== ; Name: _FileListToArrayNT7 ; Description: Lists files and\or folders in specified path(s) (Similar to using Dir with the /B Switch) ; additional features: multi-path, multi-filter, multi-exclude-filter, path format options, recursive search ; Syntax: _FileListToArrayNT7([$sPath = @ScriptDir, [$sFilter = "*", [$iSearchType, [$bRecursive = False, [$sExclude = "", [$iRetFormat = 1]]]]]]) ; Parameter(s): $sPath = optional: Search path(s), semicolon delimited (default: @ScriptDir) ; (Example: "C:\Tmp;D:\Temp") ; $sFilter = optional: Search filter(s), semicolon delimited . Wildcards allowed. (default: "*") ; (Example: "*.exe;*.txt") ; $iSearchType = Include in search: 0 = Files and Folder, 1 = Files Only, 2 = Folders Only ; $iPathType = Returned element format: 0 = file/folder name only, 1 = relative path, 2 = full path ; $bRecursive = optional: True: recursive search including all subdirectories ; False (default): search only in specified folder ; $sExclude = optional: Exclude filter(s), semicolon delimited. Wildcards allowed. ; (Example: "Unins*" will remove all files/folders that begin with "Unins") ; $iRetFormat = optional: return format ; 0 = one-dimensional array, 0-based ; 1 = one-dimensional array, 1-based (default) ; 2 = String ( "|" delimited) ; $sWorkPath = *** internal use only (do not use) *** ; Requirement(s): none ; Return Value(s): on success: 1-based or 0-based array or string (dependent on $iRetFormat) ; If no path is found, @error and @extended are set to 1, returns empty string ; If no filter is found, @error and @extended are set to 2, returns empty string ; If no data is found, @error and @extended are set to 4, returns empty string ; Author(s): Half the AutoIt Community ; ==================================================================================================== Func _FileListToArrayNT7($sPath = @ScriptDir, $sFilter = "*", $iSearchType = 0, $iPathType = 0, $bRecursive = False, $sExclude = "", $iRetFormat = 1, $sWorkPath = "(-:>firstcall<:-)") Local $hSearch, $iPCount, $iFCount, $sFile, $sFileList, $sTWorkPath If $sWorkPath == "(-:>firstcall<:-)" Then If $sPath = -1 Or $sPath = Default Then $sPath = @ScriptDir ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sPath = StringRegExpReplace(StringRegExpReplace($sPath, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check that at least one path is set If $sPath = "" Then Return SetError(1, 1, "") ;----- If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*" ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sFilter = StringRegExpReplace(StringRegExpReplace($sFilter, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check that at least one filter is set If $sFilter = "" Then Return SetError(2, 2, "") ;----- If $iSearchType <> "1" and $iSearchType <> "2" Then $iSearchType = "0" ;----- If $iPathType <> "1" And $iPathType <> "2" Then $iPathType = "0" ;----- $bRecursive = ($bRecursive = "1") ;----- If $sExclude = -1 Or $sExclude = Default Then $sExclude = "" If $sExclude Then ;prepare $sExclude ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;convert $sExclude to fit StringRegExp (not perfect but useable) $sExclude = StringRegExpReplace($sExclude, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sExclude = StringReplace($sExclude, "?", ".") $sExclude = StringReplace($sExclude, "*", ".*?") $sExclude = "(?i)\A" & StringReplace($sExclude, ";", "|") & "\z" EndIf ;----- If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1" $sWorkPath = "" EndIf Local $aPath = StringSplit($sPath, ';', 1) ;paths array Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array If $sExclude Then For $iPCount = 1 To $aPath[0] ;Path loop Local $sDelim = "|" ;reset $sDelim If StringRight($aPath[$iPCount], 1) <> "\" Then $aPath[$iPCount] &= "\" ;ensure trailing slash If $iPathType = 2 Then $sDelim &= $aPath[$iPCount] ;return full-path For $iFCount = 1 To $aFilter[0] ;filter loop If StringRegExp($aFilter[$iFCount], "[\\/:<>|]") Then ContinueLoop ;bypass filters with invalid chars $hSearch = FileFindFirstFile($aPath[$iPCount] & $aFilter[$iFCount]) If @error Then ContinueLoop Switch $iSearchType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop ;bypass folder ;check for exclude files If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sDelim & $sWorkPath & $sFile WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ;bypass file ;check for exclude folder If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sDelim & $sWorkPath & $sFile EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop ;check for exclude files/folder If StringRegExp($sFile, $sExclude) Then ContinueLoop $sFileList &= $sDelim & $sWorkPath & $sFile WEnd EndSwitch FileClose($hSearch) Next ;$iFCount - next filter ;--------------- ;optional do a recursive search If $bRecursive Then $hSearch = FileFindFirstFile($aPath[$iPCount] & "*.*") If Not @error Then While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ;bypass file ;check for exclude folder If StringRegExp($sFile, $sExclude) Then ContinueLoop ;call recursive search If $iPathType = 1 Then $sTWorkPath = $sWorkPath & $sFile & "\" $sFileList &= _FileListToArrayNT7($aPath[$iPCount] & $sFile & "\", $sFilter, $iSearchType, $iPathType, $bRecursive, $sExclude, 2, $sTWorkPath) EndIf WEnd FileClose($hSearch) EndIf EndIf Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;path loop Local $sDelim = "|" ;reset $sDelim If StringRight($aPath[$iPCount], 1) <> "\" Then $aPath[$iPCount] &= "\" ;ensure trailing slash If $iPathType = 2 Then $sDelim &= $aPath[$iPCount] ;return full-path For $iFCount = 1 To $aFilter[0] ;filter loop If StringRegExp($aFilter[$iFCount], "[\\/:<>|]") Then ContinueLoop ;bypass filters with invalid chars $hSearch = FileFindFirstFile($aPath[$iPCount] & $aFilter[$iFCount]) If @error Then ContinueLoop Switch $iSearchType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop ;bypass folder $sFileList &= $sDelim & $sWorkPath & $sFile WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ;bypass file $sFileList &= $sDelim & $sWorkPath & $sFile EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop $sFileList &= $sDelim & $sWorkPath & $sFile WEnd EndSwitch FileClose($hSearch) Next ;$iFCount - next filter ;--------------- ;optional do a recursive search If $bRecursive Then $hSearch = FileFindFirstFile($aPath[$iPCount] & "*.*") If Not @error Then While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ;bypass file ;call recursive search If $iPathType = 1 Then $sTWorkPath = $sWorkPath & $sFile & "\" $sFileList &= _FileListToArrayNT7($aPath[$iPCount] & $sFile & "\", $sFilter, $iSearchType, $iPathType, $bRecursive, $sExclude, 2, $sTWorkPath) EndIf WEnd FileClose($hSearch) EndIf EndIf Next ;$iPCount - next path EndIf ;If $sExclude ;--------------- ;set according return value If $sFileList Then Switch $iRetFormat Case 2 ;return a delimited string Return $sFileList Case 0 ;return a 0-based array Return StringSplit(StringTrimLeft($sFileList, 1), "|", 2) Case Else ;return a 1-based array Return StringSplit(StringTrimLeft($sFileList, 1), "|", 1) EndSwitch Else Return SetError(4, 4, "") EndIf EndFunc ;==>_FileListToArrayNT7 Edit1: little polish in parameter checking Edit2: header adjustment Edit3: header clarification Edit4: SetError correction (according to jpm, thanks for final decision) Edit5: Back to SetError(x, x, "")
  14. Yes it works, and could be shortened to $bRecursive = ($bRecursive = "1") ; on line, :-) I'll take over to function.
  15. If have it done this pragmatical way: If $bRecursive = -1 Or $bRecursive = Default Then $bRecursive = False If $bRecursive = 1 Then $bRecursive = True OK? Edit1: There is a logical error, i work on it. Edit2: Oh there is always the same error, i have forgotten that True = -1 So better: If $bRecursive = Default Then $bRecursive = False If $bRecursive = 1 Then $bRecursive = True
×
×
  • Create New...