Jump to content

Improvement of included _FileListToArray function.


Tlem
 Share

Recommended Posts

  • Replies 265
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Just a few more things...

1. The block of parameter edit statements don't quite function as well as they could. I worked on them a little and came up with some changes. The test program below demonstrates the changes. Run that, the window titles describe pretty well what you're seeing. I think the new behavior is preferable and would like to see the old block of edits statements replaced with the new. (The main improvements are in the handling of empty strings, $bRecursive, and garbage data)

I'm not sure, i have thought about that:

Some (philosophical) questions:

If the parameter value is garbage, should it then be changed to default or should the result being nothing?

If the parameter value is empty (ex $sPath), should it then be changed to default or should the result being nothing?

(my apprehension is, if the main program sets falsely an empty path, and _FileListToArray change this autonomous to @ScriptDir there maybe unexpected results)

And so on ...

What do you think about that?

If $sWorkPath= "/*firstcall*/" Then

$sWorkPath = ""

That's the idea i was locking for, already done.

3. (I'm nitpicking now) We haven't really abbreviated our other variable names, could we globally change $bRecursiv to $bRecursive ?

In my opinion that was no abbreviation, it was my insufficient English (in my language: recursive = rekursiv), already done.

4. (Still nitpicking) Would KaFu and Ascend4nt mind if the "Thanks" comment were pulled off the one SRE statement? A *LOT* of people have contributed to this function past and present, and we'd have a list 30-names long to name them all. I don't see those types of comments too often in production.

Already done. (compliance of KaFu and Ascend4nt presumed)

Edit: These changes will, of course, result in: _FileListToArraySuperTurbo4000PlusProWithMoreUltraPowerboost

I have had the same recommendation. :-)
Link to comment
Share on other sites

I would be good you point me to the post that describe what I should put in the standard UDF with the doc please.

I will manage the final inclusion. :)

Please give us 24 hours more, then i would belief we are ready. (no guarantee)

(if SmOke_N or others have no more suggestions) ;-)

There remains only a small decision regarding parameter checking.

Is there any native English speaking person, who can write the doc? Please come in.

(My English is surely not adequate for that work!)

Link to comment
Share on other sites

Please give us 24 hours more, then i would belief we are ready. (no guarantee)

(if SmOke_N or others have no more suggestions) ;-)

There remains only a small decision regarding parameter checking.

Is there any native English speaking person, who can write the doc? Please come in.

(My English is surely not adequate for that work!)

no problem I wait and see :)
Link to comment
Share on other sites

@extended return 0 (on folder) when it's found as first instance in *NextFile, therefore the function fails in some cases (especialy when using recursive mode).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

@extended return 0 (on folder) when it's found as first instance in *NextFile, therefore the function fails in some cases (especialy when using recursive mode).

What's wrong in real world?

I can not confirm this behaviour.

Please can you show us an example where this happens.

@Danny35d:

In my tests, searching for *.dat is always OK (compared to Windows-Search)

So i am a little bit perplexed. ;-|

Please can you also show us an example where this happens.

I will test more in a few hours (real world is calling) :-)

Thanks in advance to both.

Link to comment
Share on other sites

What's wrong in real world?

I can not confirm this behaviour.

Please can you show us an example where this happens.

#include <Array.au3>

$sMain_Path = @ScriptDir & "\~Test_Path"
$sSub_Path = $sMain_Path & "\First_Folder"

;Uncomment these two lines to see that file returned when it's in the secondly found (created) folder - but first delete the created folder after first run
;$sSub_Path2 = $sMain_Path & "\Second_Folder"
;DirCreate($sSub_Path2)

DirCreate($sSub_Path) ;Creating the folder
FileWrite($sSub_Path & "\File.txt", "") ;Just creating the file

$aFiles = _FileListToArrayNT5($sMain_Path, "*", 1, 0, 1)
_ArrayDisplay($aFiles) ;Here we got only the folder name, no File.txt

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

This should solve the problem:

If @extended Or StringInStr(FileGetAttrib($aPath[$iPCount] & $sFile), "D") Then;bypass file (for Autoit versions > 3.3.0.0)

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

@extended return 0 (on folder) when it's found as first instance in *NextFile, therefore the function fails in some cases (especialy when using recursive mode).

Wasn't that bug in FileFindNextFile addressed between beta version 3.3.1.0 and 3.3.1.1?

From the Beta 3.3.1.1 release notes:

- Fixed #969: FileFindNextFile() does not set @extended if first found is a dir. (Thanks wraithdu)

I find when running in beta mode (Alt-F5) that the function works correctly with 3.3.1.1.
Link to comment
Share on other sites

I'm not sure, i have thought about that:

Some (philosophical) questions:

If the parameter value is garbage, should it then be changed to default or should the result being nothing?

If the parameter value is empty (ex $sPath), should it then be changed to default or should the result being nothing?

(my apprehension is, if the main program sets falsely an empty path, and _FileListToArray change this autonomous to @ScriptDir there maybe unexpected results)

And so on ...

What do you think about that?

I often like to use an empty string to "skip" a parameter, there are functions here that work similarly.

The need for the $bRecursive handling was just demonstrated by MrCreator, who used a "1" to indicate a "True" condition.

Likewise, converting "True" to "1" and "False" to "0" when necessary seems logical. The conversion of "-1" to "False" for the default value of $bRecursive is certainly correct. As to handling garbage parameters, I don't know that correcting some of the parameters is any less predictable than processing them as sent. Either way, the user is likely not going to get back from the function what they wanted, and will have to correct their function call to use parameters that will result in the desired list of files/folders being returned. The extra editing does keep improper values from being processed inside the function, where they may potentially cause a fatal error.

Edit: The portion of the comments stating " (for Autoit versions > 3.3.0.0)" ought to be removed sometime prior to going into production. It is pertinent now, for testing, while the production version is 3.3.0.0, but if/when this version is added to production that portion of the comment will be outdated/unnecessary/obsolete/superfluous

Edit2: This is a question, not a suggestion (yet). Can these lines "Local $aPath = StringSplit($sPath, ';', 1) ;paths array" and

"Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array" be moved inside the "If $sWorkPath= "/*firstcall*/" Then" test??? I'll see if it causes a problem... Stripping off the "Local" tokens and moving those two lines into the "/*firstcall*/" test caused no adverse effects when running the function with multiple paths and multiple filters.

Edit3: Is there reason for the "Local" on $sDelim? Would that cause it to recreate the variable each time, rather than just assign it a new value?

Edit4: The comment for the "If $iPathType = 2" statement is at the end of the line in one case, and on a separate line in the second case. The second one ought to be put at the end of the line as well (overall function size gets one line smaller)

Edit5: I'm excited about a final version! I hope people will like the name _FileListToArraySuperTurbo4000PlusProWithMaximumUltraPowerboost :)

Edited by Spiff59
Link to comment
Share on other sites

Wasn't that bug in FileFindNextFile addressed between beta version 3.3.1.0 and 3.3.1.1?

From the Beta 3.3.1.1 release notes:

I find when running in beta mode (Alt-F5) that the function works correctly with 3.3.1.1.

Oh sorry guys. I didn't notice that i set the path to 3.3.1.0, and i do have 3.3.1.1, just forgot to swith on it :)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

@extended return 0 (on folder) when it's found as first instance in *NextFile, therefore the function fails in some cases (especialy when using recursive mode).

this has been fixed in 3.3.1.2 for ticket #969
Link to comment
Share on other sites

this has been fixed in 3.3.1.2 for ticket #969

Yes yes, when i checked the beta history i didn't notice that i checking for 3.3.1.0 :)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

We are still discussing parameter checking, and possibly a couple other minor issues, but this is the latest version that I have:

; #FUNCTION# ===========================================================================================
; Name:             _FileListToArrayNT6
; Description:      full compatible _FileListToArray replacement  (with greater performance and additional features)
;                   additional: multi-path, multi-filter, multi-exclude-filter, path format options, recursive search
; Syntax:           _FileListToArrayNT4([$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 data is found, @error is set (to 4, for backwards compatibility)
; Author(s):        Half the AutoIt Community
; ====================================================================================================

Func _FileListToArrayNT6($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
    $sWorkPath = ""
    If $sPath = -1 Or $sPath = Default Or $sPath == "" Then $sPath = @ScriptDir
    If $sFilter = -1 Or $sFilter = Default Or $sFilter == "" Then $sFilter = "*"
    If $iSearchType <> "1" and $iSearchType <> "2" Then $iSearchType = "0"
    If $iPathType <> "1" And $iPathType <> "2" Then $iPathType = "0"
    If $bRecursive = "1" Then
      $bRecursive = True
    Else
      $bRecursive = False
    EndIf
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ""
    If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1"

    If $sExclude Then
      ;prepare $sExclude
      ;strip leading and trailing spaces and spaces between semi colon delimiter
      $sExclude = StringStripWS(StringRegExpReplace($sExclude, "\s*;\s*", ";"), 3)
      ;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

    ;strip leading and trailing spaces and spaces between semi colon delimiter
    $sPath = StringStripWS(StringRegExpReplace($sPath, "\s*;\s*", ";"), 3)
    $sFilter = StringStripWS(StringRegExpReplace($sFilter, "\s*;\s*", ";"), 3)
    
  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
      $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 = 0 Then ContinueLoop ;bypass file
              ;check for exclude folder
              If StringRegExp($sFile, $sExclude) Then ContinueLoop
              $sFileList &= $sDelim & $sWorkPath & $sFile
            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 = 0 Then ContinueLoop ;bypass file
            ;check for exclude folder
            If StringRegExp($sFile, $sExclude) Then ContinueLoop
            ;call recursive search
            If $iPathType = 1 Then $sTWorkPath = $sWorkPath & $sFile & "\"
            $sFileList &= _FileListToArrayNT6($aPath[$iPCount] & $sFile & "\", $sFilter, $iSearchType, $iPathType, $bRecursive, $sExclude, 2, $sTWorkPath)
          WEnd
          FileClose($hSearch)
        EndIf
      EndIf

    Next ;$iPCount - next path

  Else ;If Not $sExclude

    For $iPCount = 1 To $aPath[0] ;path loop
      $sDelim = "|" ;reset $sDelim

      If StringRight($aPath[$iPCount], 1) <> "\" Then $aPath[$iPCount] &= "\" ;ensure trailing slash

      If $iPathType = 2 Then $sDelim &= $aPath[$iPCount] ;return full-path

      ;perform the search
      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 = 0 Then ContinueLoop ;bypass file
              $sFileList &= $sDelim & $sWorkPath & $sFile
            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 = 0 Then ContinueLoop ;bypass file
            ;call recursive search
            If $iPathType = 1 Then $sTWorkPath = $sWorkPath & $sFile & "\"
            $sFileList &= _FileListToArrayNT6($aPath[$iPCount] & $sFile & "\", $sFilter, $iSearchType, $iPathType, $bRecursive, $sExclude, 2, $sTWorkPath)
          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   ;==>_FileListToArrayNT6

Still twice as fast as the existing _FileListToArray().

All are invited to beat it, break it, or make it better.

PS: BaKaMu, by documentation, do you mean the Helpfile entry for this function? (and feel free to undo any changes you don't like in the NT6 version above)

Edit: moved paths/filters array back outside of firstcall test

Edit2: BUGS! I've found some behavior that's been in this version for a long time that needs some work. If a semi-colon (or a bunch of them) is sent as the path, the SplitString will create a paths array with an element count of 2, with both elements being empty. A backslash is then appended to each element. This causes the function to return a copy of the file/folder list of the root directory for each element. We need a one-time edit in the /*firstcall*/ section that strips leading, trailing and adjacent semi-colons from the parameter before it is loaded into the array. I assume we ought to do the same with the filter and exclude parameters. Looks like a job for (drumroll) StringRegExpReplace()?

Edited by Spiff59
Link to comment
Share on other sites

@Danny35d:

In my tests, searching for *.dat is always OK (compared to Windows-Search)

So i am a little bit perplexed. ;-|

Please can you also show us an example where this happens.

I tested the script from post #136 and Flag 0 should return 5, Flag 1 should return 5 and Flag 2 should return 0 instead they return 15, 10 and 5.

This is the code:

#include <Array.au3>

If Not FileExists(@ScriptDir & '\Testing\Files') Or Not FileExists(@ScriptDir & '\Testing\Folders') Then
    DirCreate(@ScriptDir & '\Testing\Files')
    DirCreate(@ScriptDir & '\Testing\Folders')
    For $x = 1 To 5
        FileWriteLine(@ScriptDir & '\Testing\Files\Test' & $x & '.dat', 'Testing....')
        FileWriteLine(@ScriptDir & '\Testing\Files\Test' & $x & '.data', 'Testing....')
        DirCreate(@ScriptDir & '\Testing\Folders\Folder' & $x & '.Data')
    Next
EndIf

For $x = 0 To 2
    $aFileList = _FileListToArrayNT5(@ScriptDir & '\Testing', "*.dat", $x, 2, 1)
    _ArrayDisplay($aFileList)
Next

Also tried Spiff59 from post # 155 and I get this error:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Documents and Settings\dcolon\Desktop\New AutoIt v3 Script (3).au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams

+>12:19:52 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X86 ANSI)

>Running AU3Check (1.54.16.0) from:C:\Program Files\AutoIt3\beta

+>12:19:52 AU3Check ended.rc:0

>Running:(3.3.1.1):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Documents and Settings\dcolon\Desktop\New AutoIt v3 Script (3).au3"

C:\Documents and Settings\dcolon\Desktop\New AutoIt v3 Script (3).au3 (361) : ==> Variable used without being declared.:

For $iPCount = 1 To $aPath[0]

For $iPCount = 1 To ^ ERROR

->12:19:52 AutoIT3.exe ended.rc:1

+>12:19:53 AutoIt3Wrapper Finished

>Exit code: 1 Time: 1.789

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

I tested the script from post #136 and Flag 0 should return 5, Flag 1 should return 5 and Flag 2 should return 0 instead they return 15, 10 and 5.

I see, specifying a filter of "*.dat" matches both ".dat" and ".data".

Also tried Spiff59 from post # 155 and I get this error:

I'd just moved the array definitions, then 5 minutes after I posted that I hit that same error, so I updated the post and moved them back. Bad timing on that, you copied the post before I had fixed it.
Link to comment
Share on other sites

I often like to use an empty string to "skip" a parameter, there are functions here that work similarly.

--> If $sPath = -1 Or $sPath = Default Or $sPath == "" Then $sPath = @ScriptDir

$sPath == "": I think this may be very dangerous!!

Following scenario: The main-program has a input-field for path and the files in this path should be deleted.

The user or the program are returning mistakable a empty path and then calling _FileListToArray.

FLTA says: no path then i use @ScriptDir, returns an array of the files in @ScriptDir and then erases this files.

Then the lights goes out and i hope you have a fine excuse.

--> If $sFilter = -1 Or $sFilter = Default Or $sFilter == "" Then $sFilter = "*"

$sFilter == "": Same discussion as above, but more dangerous.

Instead of nothing is returned, all is returned "*"

Then the lights never goes on again and i hope you have a good insurance.

--> If $iSearchType <> "1" And $iSearchType <> "2" Then $iSearchType = "0"

In AutoIt it is usual to use "-1" or keyword "Default" to signal a default value.

(this has to be handled inside the function, discussion of that was some posts ago)

So let's do this test, all other eventualities are handled correct with Switch...Case...Case Else...

--> If $iPathType <> "1" And $iPathType <> "2" Then $iPathType = "0"

Same as above.

--> If $bRecursive = "1" Then $bRecursive = True Else $bRecursive = False EndIf

Same as above.

--> If $sExclude = -1 Or $sExclude = Default Then $sExclude = ""

Agree

--> If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1"

Same as $iSearchType.

In summary: Let it be as in _FileListToArrayNT5 (not perfect, but usable)

Edit: The portion of the comments stating " (for Autoit versions > 3.3.0.0)" ought to be removed sometime prior to going into production.

Same idea, already done.

Edit2: This is a question, not a suggestion (yet). Can these lines "Local $aPath = StringSplit($sPath, ';', 1) ;paths array" and

"Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array" be moved inside the "If $sWorkPath= "/*firstcall*/" Then" test???

You noticed it by yourself.

Edit3: Is there reason for the "Local" on $sDelim? Would that cause it to recreate the variable each time, rather than just assign it a new value?

Yes, i have to declare a variable $sDelim :-)

I think it's no difference whether i declare it on the top of function or in this line.

I normally declare all variable with Local (inside function) or Global (outside function).

It's good programming practice and if there is a AutoItSetOption("MustDeclareVars", 1) so there is no error message.

Edit4: The comment for the "If $iPathType = 2" statement is at the end of the line in one case, and on a separate line in the second case.

Already done.

If @extended = 0 Then ContinueLoop ;bypass file

This is a little bit slower then --> If @extended Then ... EndIf <--

So where the condition has a negation or the condition is checking against a value

i have used the If...Then...Else construct, otherwise the If...ContinueLoop

(this was just a speed optimizing, look at post #136)

Edit2: BUGS! I've found some behavior that's been in this version for a long time that needs some work. If a semi-colon (or a bunch of them) is sent as the path, the SplitString will create a paths array with an element count of 2, with both elements being empty. A backslash is then appended to each element. This causes the function to return a copy of the file/folder list of the root directory for each element. We need a one-time edit in the /*firstcall*/ section that strips leading, trailing and adjacent semi-colons from the parameter before it is loaded into the array. I assume we ought to do the same with the filter and exclude parameters. Looks like a job for (drumroll) StringRegExpReplace()?

I will have a look at this (if i get ready with this post, cause you add edits again and again ;-))

Edit5: I'm excited about a final version! I hope people will like the name _FileListToArraySuperTurbo4000PlusProWithMaximumUltraPowerboost :)

There can not be a better name like this. Handy and remarkable, adequately and functional. :-)

A small step for man, a lot of typing for user!

Link to comment
Share on other sites

--> If $bRecursive = "1" Then $bRecursive = True Else $bRecursive = False EndIf

I'll acceed to the philosophy of allowing bad parameters to result in a no-return from the routine, but...

The $bRecursive line above is needed. Two different posters in this thread have already posted examples where they have used "1" for True, or "0" for False. It doesn't seem right to not accept those values for a boolean.

Yes, i have to declare a variable $sDelim :-)

Does putting "Local" in front of it cause the variable to be destroyed and recreated each loop? Is it more efficient to define it once at the top?

Looks like the semi-colon in the parms issue is yet to be addressed, and the question about filter behavior needs to be decided (.dat versus .data)

Edited by Spiff59
Link to comment
Share on other sites

I see, specifying a filter of "*.dat" matches both ".dat" and ".data".

Yes, i noticed this behavior, but sorry , this belongs to AutoIt FileFindFirstFile/FileFindNextFile

and as usual Microsofts Windows (same behavior with DIR ...).

FLTA only transfers search strings (=filters) to FileFindFirstFile/FileFindNextFile.

We shouldn't FLTA modify here.

Edited by BaKaMu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...