Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

RecFileListToArray - Deprecated


  • This topic is locked This topic is locked
328 replies to this topic

#121 megablox

megablox

    Adventurer

  • Active Members
  • PipPip
  • 110 posts

Posted 10 March 2012 - 03:48 PM

Hey, I've got this problem:

Func updateLists()    MsgBox(0, "dev", "Updating list 1")    $d=InputBox("Select a drive", "Please input an uppercase drive letter (will search X:VideoAnimes)")    $sPath = $d&":VideoAnimes"    MsgBox(0, "dev", "Will search "&$sPath)    $aArray = _RecFileListToArray($sPath, "*.*", 1)    MsgBox(0, "dev", $aArray[0]&$aArray[1]&$aArray[2]&$aArray[3]) EndFunc


I get this error:
C:Workspaceanimedb.au3 (70) : ==> Subscript used with non-Array variable.:
MsgBox(0, "dev", $aArray[0]&$aArray[1]&$aArray[2]&$aArray[3])
MsgBox(0, "dev", $aArray^ ERROR

I tried changing it to this:

Func updateLists()    MsgBox(0, "dev", "Updating list 1")    $d=InputBox("Select a drive", "Please input an uppercase drive letter (will search X:VideoAnimes)")    $sPath = $d&":VideoAnimes"    MsgBox(0, "dev", "Will search "&$sPath)    Local $aArray[10]    $aArray = _RecFileListToArray($sPath, "*.*", 1)    MsgBox(0, "dev", $aArray[0]&$aArray[1]&$aArray[2]&$aArray[3]) EndFunc


Same error, except for diff. line.

P.S:

At the top of the script, I added this:

#include <Array.au3>
#include "RecFileListToArray.au3"

Edited by megablox, 10 March 2012 - 03:50 PM.








#122 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 10 March 2012 - 03:58 PM

mehablox,

Guess what - it works for me! :bye:

The array is obviously not being created - so let us try some errorchecking to find out why. Add this new line and see what we get as an error return from the UDF: :oops:
[...] $aArray = _RecFileListToArray($sPath, "*.*", 1) MsgBox(0, "dev", "Error = " & @error) ; Add this line <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< [...]

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#123 megablox

megablox

    Adventurer

  • Active Members
  • PipPip
  • 110 posts

Posted 10 March 2012 - 04:12 PM

The output is @error = 1 @extended = 9 no files etc
Sorry for the long delay (if any)

P.S: It also returns an empty string.
P.S: It's searching inside X:VideoAnimes, I have it check inside the "I" drive (my external hard disk)

Edited by megablox, 10 March 2012 - 04:15 PM.


#124 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 10 March 2012 - 04:19 PM

megablox,

Which is what I suspected. The path exists but there appear to be no files within it. :oops:

Are there in fact any files in the path you are searching? Try running this script using another file listing function to check: :bye:
#include <Array.au3> #include <File.au3> ; changed <<<<<<<<<<<<<<<<<<<<<<<<<<< updateLists() Func updateLists()     MsgBox(0, "dev", "Updating list 1")     $d = InputBox("Select a drive", "Please input an uppercase drive letter (will search X:VideoAnimes)")     $sPath = $d & ":ProgramAu3 Scripts" ; ":VideoAnimes"     MsgBox(0, "dev", "Will search " & $sPath)     $aArray = _FileListToArray($sPath, "*.*", 1)  ; changed <<<<<<<<<<<<<<<<<<<<<<<<<<<     MsgBox(0, "dev", $aArray[0] & $aArray[1] & $aArray[2] & $aArray[3]) EndFunc   ;==>updateLists

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#125 megablox

megablox

    Adventurer

  • Active Members
  • PipPip
  • 110 posts

Posted 10 March 2012 - 04:23 PM

I:VideoAnimes it's an existing folder, and inside are 3 other folders which either contain more folders or files.
I tried the code you gave me, and I got this error =

C:Workspaceanimedb.au3 (70) : ==> Subscript used with non-Array variable.:
MsgBox(0, "dev", $aArray[0] & $aArray[1] & $aArray[2] & $aArray[3])
MsgBox(0, "dev", $aArray^ ERROR

Edited by megablox, 10 March 2012 - 04:27 PM.


#126 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 10 March 2012 - 04:28 PM

megablox,

Aha, so the files are inside other folders on the path. Then you need to search recursively within them: :bye:
#include <Array.au3> #include <RecFileListToArray.au3> updateLists() Func updateLists()     MsgBox(0, "dev", "Updating list 1")     $d = InputBox("Select a drive", "Please input an uppercase drive letter (will search X:VideoAnimes)")     $sPath = $d & ":ProgramAu3 Scripts" ; ":VideoAnimes"     MsgBox(0, "dev", "Will search " & $sPath)     $aArray = _RecFileListToArray($sPath, "*.*", 1, 1) ; We have now set the recursive flag to search within the folders on the path <<<<<<<<<<<<<<<<<<<<<<<<<<     If IsArray($aArray) Then         _ArrayDisplay($aArray) ; Either you see a list of files     Else         MsgBox(0, "Error", @error & " - " & @extended) ; Or an error MsgBox     EndIf EndFunc   ;==>updateLists

How does that work? :oops:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#127 megablox

megablox

    Adventurer

  • Active Members
  • PipPip
  • 110 posts

Posted 10 March 2012 - 04:47 PM

Hi again,

Right, that works in a way that I might be able to use, but it's not exactly what I wanted.

What I wanted was to find the list of folders inside X:VideoAnimes. I don't want the files inside those folders (atleast yet), because I want to list the folder names on a separate GUI list and then allow different functionality over there. All I wanted was the array, [0] being the number of folders, then [1] being the first folder, etc, like it should return.
I tried changing the check to be
$aArray = _RecFileListToArray($sPath, "*", 1)

Which should return anything whatsoever, should it not, including folders? Though it errors (0 - 0), confusingly.

Also, I'm unsure as to what the 1 at the end of the _RecFileListToArray call is for - does it mean only find files? In which case, I would think that's the problem as I wish to find folders. I don't explicitly need to find folders, as there won't be any files on that top level under X:VideoAnimes, only folders.

Thanks in advance!

EDIT: Right, I think this is how it goes:
The last number is what thing it searches for
0 - files & folders
1 - files
2 - folders
Am I right? :oops:

Edited by megablox, 10 March 2012 - 04:51 PM.


#128 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 10 March 2012 - 04:54 PM

megablox,

You have it - always helps to read the function header. :bye:

If you want the list of folders on that path then you need this - use "*" for folders as there might not be an extension: :doh:
#include <Array.au3> #include <RecFileListToArray.au3> updateLists() Func updateLists()     MsgBox(0, "dev", "Updating list 1")     $d = InputBox("Select a drive", "Please input an uppercase drive letter (will search X:VideoAnimes)")     $sPath = $d & ":VideoAnimes"     MsgBox(0, "dev", "Will search " & $sPath)     $aArray = _RecFileListToArray($sPath, "*", 2) ; We have now set the return flag to search for folders     If IsArray($aArray) Then         _ArrayDisplay($aArray)     Else         MsgBox(0, "Error", @error & " - " & @extended)     EndIf EndFunc   ;==>updateLists

Are we there? :oops:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#129 megablox

megablox

    Adventurer

  • Active Members
  • PipPip
  • 110 posts

Posted 10 March 2012 - 04:58 PM

Yep, it's all fine, thanks!
I'll keep messing up now, thanks for the support :]

#130 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 10 March 2012 - 05:13 PM

megablox,

My pleasure. :oops:

M23

Edited by Melba23, 10 March 2012 - 05:14 PM.
Might as well spell your nick correctly! :>

StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#131 IanN1990

IanN1990

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 532 posts

Posted 03 July 2012 - 01:24 PM

Hey

I checked the .au3 and found
_RecFileListToArray($sPath[, $sInclude_List = "*"[, $iReturn = 0[, $iRecur = 0[, $iSort = 0[, $iReturnPath = 1[, $sExclude_List = ""[, $sExclude_List_Folder]]]]]]])

Am i correct in understanding by this function can exclude folders from the list ? $sExclude_List_Folder

In which case could you help me amind my syntax a little to do that.

#include <RecFileListToArray.au3> #include <array.au3> $Array = _RecFileListToArray("D:", "*.*", 0, 1, 0, 2, "*.ini", "") _ArrayDisplay($Array)


I would like it to Exclude Doucments (D:001¦ Documents) and Favourites (D:008¦ Favorites). Is this possible ?

Edited by IanN1990, 03 July 2012 - 01:24 PM.


#132 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 04 July 2012 - 08:38 AM

IanN1990,

I would try something like this: ;)
#include <RecFileListToArray.au3> #include <array.au3> $Array = _RecFileListToArray("D:", "*.*", 0, 1, 0, 2, "*.ini", "001¦ Documents;008¦ Favorites") _ArrayDisplay($Array)

As you can see, the folders are all returned with a trailing "" so it is easy to distinguish between files and folders.

That works for me - does it for you? :)

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#133 IanN1990

IanN1990

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 532 posts

Posted 04 July 2012 - 11:29 PM

Thanks :) Seams i was using the syntax wrong

#134 Syed23

Syed23

    Mass Spammer! - It's Me

  • Active Members
  • PipPipPipPipPipPip
  • 544 posts

Posted 14 September 2012 - 03:13 PM

Thanks for this great UDF Melba23. But in my environment people are creating folder name with some special characters. so when i create a logic to get the folders name under specific folder it is excluding the folder which may contain special characters(which is default behavior). could you please suggest me how to remove that exclusion from the UDF? so that i will update my UDF and it will not exclude when it gets the list of folders from specific path!
Thank you,Regards,K.Syed Ibrahim.

#135 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 19 September 2012 - 09:07 PM

Syed23,

Could you please give me an example of a tree where the UDF does not recognize a folder name with "special characters" so that I can do some errorchecking? :)

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#136 Syed23

Syed23

    Mass Spammer! - It's Me

  • Active Members
  • PipPipPipPipPipPip
  • 544 posts

Posted 02 October 2012 - 09:36 AM

Syed23,

Could you please give me an example of a tree where the UDF does not recognize a folder name with "special characters" so that I can do some errorchecking? :)

M23


sure i will find to give any example asap :) just one more question, if i want to exclude the hidden folders and files how can i do that ? any suggestion?
Thank you,Regards,K.Syed Ibrahim.

#137 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 02 October 2012 - 09:54 AM

Syed23,

Ready when you are - until I have some evidence I cannot do anything about your problem. :)

As to excluding hidden folders and files - that would require the UDF to look at the attibutes of every single item it scanned. I fear that is likely to significantly increase the time taken to run through a tree - and not reducing the speed of the UDF is a major concern. I will look into how it might be done as a possible option, but no promises. ;)

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#138 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 02 October 2012 - 04:23 PM

Syed23,

Not returning hidden files and folders was easy to implement (just add 4 to the $iReturn value), but did have the expected effect on the time it takes to run through a folder tree. :(

A tree of some 8000 folders/files takes about 1200ms to return on my machine when I ask the UDF to return everything. When I ask it to to omit the hidden ones, it takes about 2600ms for the same tree - more than double. But I have written the code such that there is a minimal penalty if all files are to be returned - that only adds about 100ms to the current speed. ;)

Here is the new Beta version, please try it and let me know what you think: :)
AutoIt         
#include-once ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# ======================================================================================================================= ; Title .........: _RecFileListToArray ; AutoIt Version : v3.3.1.1 or higher ; Language ......: English ; Description ...: Lists files andor folders in specified path with optional recursion to defined level and result sorting ; Note ..........: ; Author(s) .....: Melba23 ; Remarks .......: - Modified Array.au3 functions - credit: Jos van der Zande, LazyCoder, Tylo, Ultima, SolidSnake and gcriaco ;                  - SRE patterns - credit: various forum members and Spiff59 in particular ;                  - Despite the name, this UDF is iterative, not recursive ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _RecFileListToArray: Lists files andor folders in a specified path with optional recursion to defined level and result sorting ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _RFLTA_ListToMask ......; Convert include/exclude lists to SRE format ; _RFLTA_AddToList .......; Add element to list which is resized if necessary ; _RFLTA_AddFileLists ....; Add internal lists after resizing and optional sorting ; _RFLTA_FileListSearch ..; Search file match list for files associated with a folder ; _RFLTA_ArraySort .......; Wrapper for QuickSort function ; _RFLTA_QuickSort .......: Recursive array sort ; _RFLTA_ArrayConcatenate : Join 2 arrays ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _RecFileListToArray ; Description ...: Lists files andor folders in a specified path with optional recursion to defined level and result sorting ; Syntax.........: _RecFileListToArray($sPath[, $sInclude_List = "*"[, $iReturn = 0[, $iRecur = 0[, $iSort = 0[, $iReturnPath = 1[, $sExclude_List = ""[, $sExclude_List_Folder]]]]]]]) ; Parameters ....: $sPath - Initial path used to generate filelist.  If path ends in  then folders will be returned with an ending ;                  $sInclude_List - Optional: filter for included results (default "*"). Multiple filters must be separated by ";" ;                  $iReturn - Optional: specifies whether to return files, folders or both ;                             0 - Return both files and folders (Default) ;                                 If non-recursive Include/Exclude_List applies to files and folders ;                                 If recursive Include/Exclude_List applies to files only, all folders are searched unless excluded using $sExclude_List_Folder ;                             1 - Return files only    - Include/Exclude_List applies to files only, all folders searched if recursive ;                             2 - Return folders only  - Include/Exclude_List applies to folders only for searching and return ;                             +4 = Exclude hidden files and folders hidden files (default all files returned) ;                  $iRecur - Optional: specifies whether to search recursively in subfolders and to what level ;                            1 - Search in all subfolders (unlimited recursion) ;                            0 - Do not search in subfolders (Default) ;                            Negative integer - Search in subfolders to specified depth ;                  $iSort - Optional: sort ordered in alphabetical and depth order ;                            0 - Not sorted (Default) ;                            1 - Sorted ;                            2 - Sorted with faster algorithm (assumes files sorted within each folder - requires NTFS drive) ;                  $iReturnPath - Optional: specifies displayed path of results ;                                 0 - File/folder name only ;                                 1 - Relative to initial path (Default) ;                                 2 - Full path included ;                  $sExclude_List - Optional: filter for excluded results (default ""). Multiple filters must be separated by ";" ;                  $sExclude_List_Folder - Optional: only used if $iReturn = 0 AND $iRecur = 1 to exclude folders matching the filter ; Requirement(s).: v3.3.1.1 or higher ; Return values .: Success: One-dimensional array made up as follows: ;                  |$array[0] = Number of FilesFolders returned ;                  |$array[1] = 1st FileFolder ;                  |$array[2] = 2nd FileFolder ;                  |... ;                  |$array[n] = nth FileFolder ;                    Failure: Null string and @error = 1 with @extended set as follows: ;                  |1 = Path not found or invalid ;                  |2 = Invalid $sInclude_List ;                  |3 = Invalid $iReturn ;                  |4 = Invalid $iRecur ;                  |5 = Invalid $iSort ;                  |6 = Invalid $iReturnPath ;                  |7 = Invalid $sExclude_List ;                  |8 = Invalid $sExclude_List_Folder ;                  |9 = No files/folders found ; Author ........: Melba23 ; Remarks .......: Compatible with existing _FileListToArray syntax ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _RecFileListToArray_Hidden($sInitialPath, $sInclude_List = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "", $sExclude_List_Folder = "")     Local $asReturnList[100] = [0], $asFileMatchList[100] = [0], $asRootFileMatchList[100] = [0], $asFolderMatchList[100] = [0], $asFolderSearchList[100] = [1]     Local $sFolderSlash = "", $iMaxLevel, $sInclude_File_Mask, $sExclude_File_Mask, $sInclude_Folder_Mask = ".+", $sExclude_Folder_Mask = ":"     Local $hSearch, $fFolder, $sRetPath = "", $sCurrentPath, $sName     Local $asFolderFileSectionList[100][2] = [[0, 0]], $sFolderToFind, $iFileSectionStartIndex, $iFileSectionEndIndex     ; Check for valid path     If Not FileExists($sInitialPath) Then Return SetError(1, 1, "")     ; Check if folders should have trailing  and ensure that initial path does have one     If StringRight($sInitialPath, 1) = "" Then         $sFolderSlash = ""     Else         $sInitialPath = $sInitialPath & ""     EndIf     ; Add path to folder search list     $asFolderSearchList[1] = $sInitialPath     ; Check for hidden parameter     Local $fHide_Hidden = False     If $iReturn > 3 Then         $fHide_Hidden = True         $iReturn -= 4     EndIf     ; Check for valid recur value     If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 4, "")     ; If required, determine  count for max recursive level setting     If $iRecur < 0 Then         StringReplace($sInitialPath, "", "", 2)         $iMaxLevel = @extended - $iRecur     EndIf     ; Create Include mask for files     If $sInclude_List = "*" Then         $sInclude_File_Mask = ".+"     Else         If Not _RFLTA_ListToMask($sInclude_File_Mask, $sInclude_List) Then Return SetError(1, 2, "")     EndIf     ; Set Include mask for folders     Switch $iReturn         Case 0             ; Folders affected by mask if not recursive             Switch $iRecur                 Case 0                     ; Folders match mask for compatibility                     $sInclude_Folder_Mask = $sInclude_File_Mask                 ;Case Else                     ; All folders match             EndSwitch         ;Case 1             ; All folders match         Case 2             ; Folders affected by mask             $sInclude_Folder_Mask = $sInclude_File_Mask     EndSwitch     ; Create Exclude List mask for files     If $sExclude_List = "" Then         $sExclude_File_Mask = ":" ; Set unmatchable mask     Else         If Not _RFLTA_ListToMask($sExclude_File_Mask, $sExclude_List) Then Return SetError(1, 7, "")     EndIf     ; Set Exclude mask for folders     Switch $iReturn         Case 0             ; Folders affected by mask if not recursive             Switch $iRecur                 Case 0                     ; Folders match mask for compatibility                     $sExclude_Folder_Mask = $sExclude_File_Mask                 Case Else                     ; Exclude defined folders as set in extended                     If $sExclude_List_Folder <> "" Then                         If Not _RFLTA_ListToMask($sExclude_Folder_Mask, $sExclude_List_Folder) Then Return SetError(1, 8, "")                     EndIf             EndSwitch         ;Case 1             ; All folders match         Case 2             ; Folders affected by normal mask             $sExclude_Folder_Mask = $sExclude_File_Mask     EndSwitch     ; Verify other parameters     If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 3, "")     If Not ($iSort = 0 Or $iSort = 1 Or $iSort = 2) Then Return SetError(1, 5, "")     If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 6, "")     ; Search within listed folders     While $asFolderSearchList[0] > 0         ; Set path to search         $sCurrentPath = $asFolderSearchList[$asFolderSearchList[0]]         ; Reduce folder search list count         $asFolderSearchList[0] -= 1         ; Determine return path to add to file/folder name         Switch $iReturnPath             ; Case 0 ; Name only             ; Leave as ""             Case 1 ;Relative to initial path                 $sRetPath = StringReplace($sCurrentPath, $sInitialPath, "")             Case 2 ; Full path                 $sRetPath = $sCurrentPath         EndSwitch         ; Get search handle         $hSearch = FileFindFirstFile($sCurrentPath & "*")         ; If sorting files and folders with paths then store folder name and position of associated files in list         If $iReturn = 0 And $iSort And $iReturnPath Then             _RFLTA_AddToList($asFolderFileSectionList, $sRetPath, $asFileMatchList[0] + 1)         EndIf         ; If folder empty move to next in list         If $hSearch = -1 Then             ContinueLoop         EndIf         ; Search folder         While 1             $sName = FileFindNextFile($hSearch)             ; Check for end of folder             If @error Then                 ExitLoop             EndIf             ; Set subfolder flag - @extended set in 3.3.1.1 +             $fFolder = @extended             ; Check for hidden attributes if needed and skip if found             If $fHide_Hidden And StringInStr(FileGetAttrib($sCurrentPath & $sName), "H") Then                 ContinueLoop             EndIf             ; If folder then check whether to add to search list             If $fFolder Then                 Select                     Case $iRecur < 0 ; Check recur depth                         StringReplace($sCurrentPath, "", "", 0, 2)                         If @extended < $iMaxLevel Then                             ContinueCase ; Check if matched to masks                         EndIf                     Case $iRecur = 1 ; Full recur                         If Not StringRegExp($sName, $sExclude_Folder_Mask) Then ; Add folder unless excluded                             _RFLTA_AddToList($asFolderSearchList, $sCurrentPath & $sName & "")                         EndIf                     ; Case $iRecur = 0 ; Never add                         ; Do nothing                 EndSelect             EndIf             If $iSort Then ; Save in relevant folders for later sorting                 If $fFolder Then                     If StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then                         _RFLTA_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash)                     EndIf                 Else                     If StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then                         ; Select required list for files                         If $sCurrentPath = $sInitialPath Then                             _RFLTA_AddToList($asRootFileMatchList, $sRetPath & $sName)                         Else                             _RFLTA_AddToList($asFileMatchList, $sRetPath & $sName)                         EndIf                     EndIf                 EndIf             Else ; Save directly in return list                 If $fFolder Then                     If $iReturn <> 1 And StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then                         _RFLTA_AddToList($asReturnList, $sRetPath & $sName & $sFolderSlash)                     EndIf                 Else                     If $iReturn <> 2 And StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then                         _RFLTA_AddToList($asReturnList, $sRetPath & $sName)                     EndIf                 EndIf             EndIf         WEnd         ; Close current search         FileClose($hSearch)     WEnd     If $iSort Then         ; Check if any file/folders have been added depending on required return         Switch $iReturn             Case 0 ; If no folders then number of files is immaterial                 If $asRootFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")             Case 1                 If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 Then Return SetError(1, 9, "")             Case 2                 If $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")         EndSwitch         Switch $iReturn             Case 2 ; Folders only                 ; Correctly size folder match list                 ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]                 ; Copy size folder match array                 $asReturnList = $asFolderMatchList                 ; Simple sort list                 _RFLTA_ArraySort($asReturnList)             Case 1 ; Files only                 If $iReturnPath = 0 Then ; names only so simple sort suffices                     ; Combine file match lists                     _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)                     ; Simple sort combined file list                     _RFLTA_ArraySort($asReturnList)                 Else                     ; Combine sorted file match lists                     _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)                 EndIf             Case 0 ; Both files and folders                 If $iReturnPath = 0 Then ; names only so simple sort suffices                     ; Combine file match lists                     _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)                     ; Set correct count for folder add                     $asReturnList[0] += $asFolderMatchList[0]                     ; Resize and add file match array                     ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]                     _RFLTA_ArrayConcatenate($asReturnList, $asFolderMatchList)                     ; Simple sort final list                     _RFLTA_ArraySort($asReturnList)                 Else                     ; Size return list                     Local $asReturnList[$asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0] + 1]                     $asReturnList[0] = $asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0]                     ; Sort root file list                     _RFLTA_ArraySort($asRootFileMatchList, 1, $asRootFileMatchList[0])                     ; Add the sorted root files at the top                     For $i = 1 To $asRootFileMatchList[0]                         $asReturnList[$i] = $asRootFileMatchList[$i]                     Next                     ; Set next insertion index                     Local $iNextInsertionIndex = $asRootFileMatchList[0] + 1                     ; Sort folder list                     _RFLTA_ArraySort($asFolderMatchList, 1, $asFolderMatchList[0])                     ; Work through folder list                     For $i = 1 To $asFolderMatchList[0]                         ; Format folder name for search                         If $sFolderSlash Then                             $sFolderToFind = $asFolderMatchList[$i]                         Else                             $sFolderToFind = $asFolderMatchList[$i] & ""                         EndIf                         ; Find folder in FolderFileSectionList                         For $j = 1 To $asFolderFileSectionList[0][0]                             If $sFolderToFind = $asFolderFileSectionList[$j][0] Then ExitLoop                         Next                         ; Set file list indexes                         $iFileSectionStartIndex = $asFolderFileSectionList[$j][1]                         If $j = $asFolderFileSectionList[0][0] Then                             $iFileSectionEndIndex = $asFileMatchList[0]                         Else                             $iFileSectionEndIndex = $asFolderFileSectionList[$j + 1][1] - 1                         EndIf                         ; Sort files if required                         If $iSort = 1 Then                             _RFLTA_ArraySort($asFileMatchList, $iFileSectionStartIndex, $iFileSectionEndIndex)                         EndIf                         ; Add folder to return list                         $asReturnList[$iNextInsertionIndex] = $asFolderMatchList[$i]                         $iNextInsertionIndex += 1                         ; Add files to return list                         For $j = $iFileSectionStartIndex To $iFileSectionEndIndex                             $asReturnList[$iNextInsertionIndex] = $asFileMatchList[$j]                             $iNextInsertionIndex += 1                         Next                     Next                 EndIf         EndSwitch     Else ; No sort         ; Check if any file/folders have been added         If $asReturnList[0] = 0 Then Return SetError(1, 9, "")         ; Remove any unused return list elements from last ReDim         ReDim $asReturnList[$asReturnList[0] + 1]     EndIf     Return $asReturnList EndFunc   ;==>_RecFileListToArray ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_ListToMask ; Description ...: Convert include/exclude lists to SRE format ; Syntax ........: _RFLTA_ListToMask(ByRef $sMask, $sList) ; Parameters ....: $asMask - Include/Exclude mask to create ;                  $asList - Include/Exclude list to convert ; Return values .: Success: 1 ;                  Failure: 0 ; Author ........: SRE patterns developed from those posted by various forum members and Spiff59 in particular ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_ListToMask(ByRef $sMask, $sList)     ; Check for invalid characters within list     If StringRegExp($sList, "|/|:|<|>||") Then Return 0     ; Strip WS and insert | for ;     $sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "s*;s*", ";"), 3), ";", "|")     ; Convert to SRE pattern     $sList = StringReplace(StringReplace(StringRegExpReplace($sList, "[][$^.{}()+-]", "$0"), "?", "."), "*", ".*?")     ; Add prefix and suffix     $sMask =  "(?i)^(" & $sList & ")z"     Return 1 EndFunc   ;==>_RFLTA_ListToMask ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_AddToList ; Description ...: Add element to [?] or [?][2] list which is resized if necessary ; Syntax ........: _RFLTA_AddToList(ByRef $asList, $vValue_0, [$vValue_1]) ; Parameters ....: $aList - List to be added to ;                  $vValue_0 - Value to add (to [0] element in [?][2] array if $vValue_1 exists) ;                  $vValue_1 - Value to add to [1] element in [?][2] array (optional) ; Return values .: None - array modified ByRef ; Author ........: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_AddToList(ByRef $aList, $vValue_0, $vValue_1 = -1)     If $vValue_1 = -1 Then ; [?] array         ; Increase list count         $aList[0] += 1         ; Double list size if too small (fewer ReDim needed)         If UBound($aList) <= $aList[0] Then ReDim $aList[UBound($aList) * 2]         ; Add value         $aList[$aList[0]] = $vValue_0     Else ; [?][2] array         $aList[0][0] += 1         If UBound($aList) <= $aList[0][0] Then ReDim $aList[UBound($aList) * 2][2]         $aList[$aList[0][0]][0] = $vValue_0         $aList[$aList[0][0]][1] = $vValue_1     EndIf EndFunc   ;==>_RFLTA_AddToList ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_AddFileLists ; Description ...: Add internal lists after resizing and optional sorting ; Syntax ........: _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2[, $iSort = 0]) ; Parameters ....: $asReturnList - Base list ;                  $asRootFileMatchList - First list to add ;                  $asFileMatchList - Second list to add ;                  $iSort - (Optional) Whether to sort lists before adding ;                  |$iSort = 0 (Default) No sort ;                  |$iSort = 1 Sort in descending alphabetical order ; Return values .: None - array modified ByRef ; Author ........: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2, $iSort = 0)     ; Correctly size root file match array     ReDim $asSource_1[$asSource_1[0] + 1]     ; Simple sort root file match array if required     If $iSort = 1 Then _RFLTA_ArraySort($asSource_1)     ; Copy root file match array     $asTarget = $asSource_1     ; Add file match count     $asTarget[0] += $asSource_2[0]     ; Correctly size file match array     ReDim $asSource_2[$asSource_2[0] + 1]     ; Simple sort file match array if required     If $iSort = 1 Then _RFLTA_ArraySort($asSource_2)     ; Add file match array     _RFLTA_ArrayConcatenate($asTarget, $asSource_2) EndFunc   ;==>_RFLTA_AddFileLists ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_FileListSearch ; Description ...: Search file array for beginning and end indices of folder associated files ; Syntax ........: _RFLTA_FileListSearch(Const ByRef $avArray, $vValue) ; Parameters ....: $avArray - Array to search ($asFileMatchList) ;                  $vValue  - Value to search for (Folder name from $asFolderMatchList) ;                  $iIndex  - Index to begin search (search down from here - and then from here to top if not found) ;                  $sSlash  -  if folder names end in  - else empty string ; Return values .: Success: Array holding top and bottom indices of folder associated files ;                  Failure: Returns -1 ; Author ........: Melba23 ; Modified.......: ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_FileListSearch(Const ByRef $avArray, $vValue, $iIndex, $sSlash)     Local $aRet[2]     ; Add final  if required     If Not $sSlash Then $vValue &= ""     ; Start by getting top match - search down from start index     For $i = $iIndex To $avArray[0]         ; SRE gives path less filename         If StringRegExpReplace($avArray[$i], "(^.*)(.*)", "1") = $vValue Then ExitLoop     Next     If $i > $avArray[0] Then         ; No match found so look from start index upwards         If $iIndex = $avArray[0] Then $iIndex -= 1         For $i = $iIndex + 1 To 1 Step -1             If StringRegExpReplace($avArray[$i], "(^.*)(.*)", "1") = $vValue Then ExitLoop         Next         ; If still no match - return " nothing found" for empty folder         If $i = 0 Then Return SetError(1, 0, "")         ; Set index of bottom file         $aRet[1] = $i         ; Now look for top match         For $i = $aRet[1] To 1 Step -1             If StringRegExpReplace($avArray[$i], "(^.*)(.*)", "1") <> $vValue Then ExitLoop         Next         ; Set top match         $aRet[0] = $i + 1     Else         ; Set index of top associated file         $aRet[0] = $i         ; Now look for bottom match - find first file which does not match         For $i = $aRet[0] To $avArray[0]             If StringRegExpReplace($avArray[$i], "(^.*)(.*)", "1") <> $vValue Then ExitLoop         Next         ; Set bottom match         $aRet[1] = $i - 1     EndIf     Return $aRet EndFunc   ;==>_RFLTA_FileListSearch ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_ArraySort ; Description ...: Wrapper for QuickSort function ; Syntax ........: _RFLTA_ArraySort(ByRef $avArray) ; Parameters ....: $avArray - Array to sort ;                  $iStart  - Index to start sort ;                  $iEnd    - Index to end sort ; Return values .: None - array modified ByRef ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_ArraySort(ByRef $avArray, $iStart = 1, $iEnd = -99)     If $iEnd = -99 Then $iEnd = UBound($avArray) - 1     _RFLTA_QuickSort($avArray, $iStart, $iEnd) EndFunc   ;==>_RFLTA_ArraySort ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_QuickSort ; Description ...: Recursive array sort ; Syntax ........: _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd) ; Parameters ....: $avArray - Array to sort in descending alphabetical order ;                  $iStart - Start index ;                  $iEnd - End index ; Return values .: None - array modified ByRef ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Melba23 ; Remarks .......: This function is used internally by _RFLTA_ArraySort ; =============================================================================================================================== Func _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)     Local $vTmp     If ($iEnd - $iStart) < 15 Then         Local $i, $j, $vCur         For $i = $iStart + 1 To $iEnd             $vTmp = $avArray[$i]             If IsNumber($vTmp) Then                 For $j = $i - 1 To $iStart Step -1                     $vCur = $avArray[$j]                     If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop                     $avArray[$j + 1] = $vCur                 Next             Else                 For $j = $i - 1 To $iStart Step -1                     If (StringCompare($vTmp, $avArray[$j]) >= 0) Then ExitLoop                     $avArray[$j + 1] = $avArray[$j]                 Next             EndIf             $avArray[$j + 1] = $vTmp         Next         Return     EndIf     Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)], $fNum = IsNumber($vPivot)     Do         If $fNum Then             While ($avArray[$L] < $vPivot And IsNumber($avArray[$L])) Or (Not IsNumber($avArray[$L]) And StringCompare($avArray[$L], $vPivot) < 0)                 $L += 1             WEnd             While ($avArray[$R] > $vPivot And IsNumber($avArray[$R])) Or (Not IsNumber($avArray[$R]) And StringCompare($avArray[$R], $vPivot) > 0)                 $R -= 1             WEnd         Else             While (StringCompare($avArray[$L], $vPivot) < 0)                 $L += 1             WEnd             While (StringCompare($avArray[$R], $vPivot) > 0)                 $R -= 1             WEnd         EndIf         If $L <= $R Then             $vTmp = $avArray[$L]             $avArray[$L] = $avArray[$R]             $avArray[$R] = $vTmp             $L += 1             $R -= 1         EndIf     Until $L > $R     _RFLTA_QuickSort($avArray, $iStart, $R)     _RFLTA_QuickSort($avArray, $L, $iEnd) EndFunc   ;==>_RFLTA_QuickSort ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RFLTA_ArrayConcatenate ; Description ...: Joins 2 arrays ; Syntax ........: _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource) ; Parameters ....: $avArrayTarget - Base array ;                  $avArraySource - Array to add from element 1 onwards ; Return values .: None - array modified ByRef ; Author ........: Ultima ; Modified.......: Melba23 ; Remarks .......: This function is used internally by _RecFileListToArray ; =============================================================================================================================== Func _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)     Local $iUBoundTarget = UBound($avArrayTarget) - 1, $iUBoundSource = UBound($avArraySource)     ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]     For $i = 1 To $iUBoundSource - 1         $avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]     Next EndFunc   ;==>_RFLTA_ArrayConcatenate


Anyone else reading,

Would this be a useful addition to the released UDF? :huh:

M23
  • CaptainGadget likes this
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#139 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 9,531 posts

Posted 02 October 2012 - 04:34 PM

You could technically do it with a RegEx and have it exclude any attribute chosen rather than just hidden, because in general, System files/folders are "hidden" from the normal display in Windows Explorer.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to an XP machine, and I'm not going to.

 

How to ask questions the smart way!

 

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.
Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.
_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.


#140 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 19,857 posts

Posted 02 October 2012 - 04:51 PM

BrewManNH,

Good idea on the RegEx - but what do you think of the idea of making this added functionality part of the release version given that there will be a performance penalty of about 10% even if you return everything. I am very ambivalent as to its usefulness - how often will you want to omit hidden files in normal use? :huh:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users