Jump to content

Recommended Posts

  • Moderators
Posted

Info,

I would think a combination of:

_FileListToArray

UBound

GUICtrlCreateListView

GUICtrlSetData

For...Next

and couple of If...Then lines

should do it without too much problem! >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Info,

I look forward to it! >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

After 50 minutes I've been trying to get it to work with the For...To...Next statement and failed, I tried to do it with the Do...Until statement and got it to work.

My successful Do...Until try:

$i = 1
$FileList = _FileListToArray('C:\')
Do
    MsgBox(0,"",$FileList[$i])
    $i += 1
Until $i = UBound($FileList)

My failure For...To...Next try:

For $i = $FileList[1] To $FileList[UBound($FileList)]
    MsgBox(0,"",$i)
Next

Could someone tell me what went wrong with the For statement?

  • Moderators
Posted

Info,

Try this - you need the array indices, not the values:

For $i = 1 To UBound($FileList) - 1
    MsgBox(0,"",$FileList[$i])
Next

My version of the whole script if you really want to look >_< :

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>
#include <File.au3>

$sPath = "M:\Program\Au3 Scripts"

If Not FileExists($sPath) Then
    MsgBox(0, "Error", "Invalid path")
    Exit
EndIf

$aFiles = _FileListToArray("Your_Folder_Name", "*", 1)

If Not IsArray($aFiles) Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

$hGUI = GUICreate($sPath, 500, 500)

$hList = GUICtrlCreateListView("_", 10, 10, 480, 250, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetColumnWidth(-1, 0, 480)

For $i = 1 to UBound($aFiles) - 1
    GUICtrlCreateListViewItem($aFiles[$i], $hList)
Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

I did say you needed a few If...Then lines.... :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Just one more question:

How can I add more than one file filter in _FileListToArray()?

Edited by Info
  • Moderators
Posted

Info,

You cannot!

Two solutions:

1. Run _FileListToArray several times with the different filters and then use _ArrayConcatenate to join them all together. Just do not forget to _ArrayDelete the [0] element each time!

2. Look for one of the many "improved" _FileListToArray functions which litter these forums. This is my version:

#include-once

; #FUNCTION# ====================================================================================================================
; Name...........: _FileListToArrayEx
; Description ...: Lists files and\or folders in a specified path with optional recursion.  Compatible with existing _FileListToArray syntax
; Syntax.........: _FileListToArrayEx($sPath[, $sInclude_List = "*"[, $iReturn = 0[, $fRecur = 0[, $sExclude_List = ""[, $iFullPath = 0]]]]])
; Parameters ....: $sPath   - Initial path used to generate filelist
;                  $sInclude_List - Optional: the filter for included results (default is "*"). Multiple filters must be separated by ";"
;                  $iReturn   - Optional: specifies whether to return files, folders or both
;                  |$iReturn=0 (Default) Return both files and folders
;                  |$iReturn=1 Return files only
;                  |$iReturn=2 Return folders only
;                  $fRecur  - Optional: specifies whether to search in subfolders
;                  |$fRecur=0 (Default) Do not search in subfolders
;                  |$fRecur=1 Search in subfolders
;                  $sExclude_List - Optional: the filter for excluded results (default is ""). Multiple filters must be separated by ";"
;                  $iFullPath  - Optional: specifies path of result string
;                  |$iFullPath=0 (Default) Initial path not included
;                  |$iFullPath=1 Initial path included
;                  |$iFullPath=2 File/folder name only
; Requirement(s).: v3.3.1.1 or higher
; Return values .: Success:  One-dimensional array made up as follows:
;                  |$array[0] = Number of Files\Folders returned
;                  |$array[1] = 1st File\Folder
;                  |$array[2] = 2nd File\Folder
;                  |...
;                  |$array[n] = nth File\Folder
;                  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 $fRecur
;                  |5 = Invalid $sExclude_List
;                  |6 = Invalid $iFullPath
;                  |7 = No files/folders found
; Author ........: Melba23 using SRE code from forums
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _FileListToArrayEx($sInitialPath, $sInclude_List = "*", $iReturn = 0, $fRecur = 0, $sExclude_List = "", $iFullPath = 0)

    Local $asReturnList[1] = [0], $asFolderList[3] = [1], $sInclude_List_Mask, $sExclude_List_Mask
    Local $sCurrentPath, $hSearch, $sReturnPath = "", $sName, $fFolder

    ; Check valid path
    If Not FileExists($sInitialPath) Then Return SetError(1, 1, "")
    ; Ensure trailing \
    If StringRight($sInitialPath, 1) <> "\" Then $sInitialPath = $sInitialPath & "\"
    ; Add path to folder list
    $asFolderList[1] = $sInitialPath

    ; Determine Filter mask for SRE check
    If StringRegExp($sInclude_List, "\\|/|:|\<|\>|\|") Then Return SetError(1, 2, "") ; Check for invalid characters
    $sInclude_List = StringReplace(StringStripWS(StringRegExpReplace($sInclude_List, "\s*;\s*", ";"), 3), ";", "|") ; Strip WS and swap :/|
    $sInclude_List_Mask = "(?i)^" & StringReplace(StringReplace(StringReplace($sInclude_List, ".", "\."), "*", ".*"), "?", ".") & "\z" ; Convert to SRE pattern

    ; Determine Exclude mask for SRE check
    If $sExclude_List = "" Then
        $sExclude_List_Mask = ":" ; Set unmatchable mask
    Else
        If StringRegExp($sExclude_List, "\\|/|:|\<|\>|\|") Then Return SetError(1, 5, "") ; Check for invalid characters
        $sExclude_List = StringReplace(StringStripWS(StringRegExpReplace($sExclude_List, "\s*;\s*", ";"), 3), ";", "|") ; Strip WS and swap ;/|
        $sExclude_List_Mask = "(?i)^" & StringReplace(StringReplace(StringReplace($sInclude_List, ".", "\."), "*", ".*"), "?", ".") & "\z" ; Convert to SRE pattern
    EndIf

    ; Verify other parameter values
    If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 3, "")
    If Not ($fRecur = 0 Or $fRecur = 1) Then Return SetError(1, 4, "")
    If Not ($iFullPath = 0 Or $iFullPath = 1 Or $iFullPath = 2) Then Return SetError(1, 6, "")

    ; Search in listed folders
    While $asFolderList[0] > 0

        ; Set path to search
        $sCurrentPath = $asFolderList[$asFolderList[0]]
        ; Reduce folder array count
        $asFolderList[0] -= 1
        ; Get search handle
        $hSearch = FileFindFirstFile($sCurrentPath & "*")
        ; If folder empty move to next in list
        If $hSearch = -1 Then ContinueLoop

        ; Determine path to add to file/folder name
        Switch $iFullPath
            Case 0 ; Initial path not included
                $sReturnPath = StringReplace($sCurrentPath, $sInitialPath, "")
            Case 1 ; Initial path included
                $sReturnPath = $sCurrentPath
            ; Case 2 ; Name only so leave as ""
        EndSwitch

        ; Search folder
        While 1
            $sName = FileFindNextFile($hSearch)
            ; Check for end of folder
            If @error Then ExitLoop
            ; Check for subfolder - @extended set in 3.3.1.1 +
            $fFolder = @extended

            ; If recursive search, add subfolder to folder list
            If $fRecur And $fFolder Then
                ; Increase folder array count
                $asFolderList[0] += 1
                ; Double folder array size if too small (fewer ReDim needed)
                If UBound($asFolderList) <= $asFolderList[0] + 1 Then ReDim $asFolderList[UBound($asFolderList) * 2]
                ; Add subfolder to list
                $asFolderList[$asFolderList[0]] = $sCurrentPath & $sName & "\"
            EndIf

            ; Check file/folder type against required return value and file/folder name against Include/Exclude masks
            If $fFolder + $iReturn <> 2 And StringRegExp($sName, $sInclude_List_Mask) And Not StringRegExp($sName, $sExclude_List_Mask) Then
                ; Increase return array count
                $asReturnList[0] += 1
                ; Double return array size if too small (fewer ReDim needed)
                If UBound($asReturnList) <= $asReturnList[0] Then ReDim $asReturnList[UBound($asReturnList) * 2]
                ; Add required path to file/folder name and add to array
                $asReturnList[$asReturnList[0]] = $sReturnPath & $sName
            EndIf
        WEnd

        ; Close current search
        FileClose($hSearch)

    WEnd

    ; Check if any file/folders to return
    If $asReturnList[0] = 0 Then Return SetError(1, 7, "")
    ; Remove unused return array elements from last ReDim
    ReDim $asReturnList[$asReturnList[0] + 1]

    Return $asReturnList

EndFunc   ;==>_FileListToArrayEx

Have fun!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

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