Jump to content
Sign in to follow this  
mattfaust

List View help

Recommended Posts

mattfaust

I need some help, I have cobbled together a little script that scans a directory and makes a array of the subdirectories.

My goal it to present a list of the sub dirs it found and let the user select one for back-up

I am using the help example of Listview to display the array - but Im having some issues.

1- when the selectio is made, "Backup selected" btn is pressed, the msgbox has a " | " after ever directory name, where is that coming from?

2- I dont know how to dynamically create the listview items for every sub directory found - since the number changes when a subdir is created or deleted - any suggestion there?

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

;List of all sub-directories   in dir cmd -add /S for full path
Local $sSortedDir = StringStripWS(_GetDOSOutput('dir "C:\Program Files\AutoIt3" /A:-A /B /O:N'), 3)
;-----------------------
;ConsoleWrite(_GetDOSOutput('dir /?') & @CRLF) ; Dir help
ConsoleWrite($sSortedDir & @CRLF)
;-------------------

Local $ListDirs = StringSplit($sSortedDir, @CRLF, 3);Change string of sub-directories into an array of sub-directories.
;
Local $DirCount = _ArrayMaxIndex($ListDirs, 0,1) ; get the number of directories found,* NOTE* array starting at zero

;------------------------------------------------------------------------------



Example()

Func Example()
    Local  $msg

    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF)  ; will change background color

    Local $listview = GUICtrlCreateListView("Folders found ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    Local $button = GUICtrlCreateButton("Backup Selected?", 10, 170, 150, 20)
    Local $item1 = GUICtrlCreateListViewItem($ListDirs[0], $listview)
    Local $item2 = GUICtrlCreateListViewItem($ListDirs[1], $listview)
    Local $item3 = GUICtrlCreateListViewItem($ListDirs[2], $listview)
    Local $item4 = GUICtrlCreateListViewItem($ListDirs[3], $listview)
    Local $item5 = GUICtrlCreateListViewItem($ListDirs[4], $listview)
    Local $item6 = GUICtrlCreateListViewItem($ListDirs[5], $listview)
    ;Local $item7 = GUICtrlCreateListViewItem($ListDirs[6], $listview)
    ;Local $item8 = GUICtrlCreateListViewItem($ListDirs[7], $listview)
    ;Local $item9 = GUICtrlCreateListViewItem($ListDirs[8], $listview)
    ;Local $input1 = GUICtrlCreateInput("", 20, 200, 150)
    ;GUICtrlSetState(-1, $GUI_DROPACCEPTED)   ; to allow drag and dropping
    GUISetState()
    ;GUICtrlSetData($item2, $ListDirs[0])
    ;GUICtrlSetData($item3, "||COL33")
    ;GUICtrlDelete($item1)

    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $button
                MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example




Func _GetDOSOutput($command)
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return $text
EndFunc ;==>_GetDOSOutput

Share this post


Link to post
Share on other sites
PsaltyDS

Use _FileListToArray() to get a list of subdirectories in an array, then just loop through the array to add items to the ListView.

The pipe "|" symbol is just a delimiter for multiple columns selected. You can StringSplit() the selections to an array.

More advanced functions are available as _GuiCtrlListView_* UDFs, but if you use those then use the UDFs to create and populate the ListView also. Strange behavior ensues if you create the control with the native functions, then modify them with the UDFs.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.