Jump to content

Selecting a number of file from a list


Recommended Posts

Hey,

I want to make a GUI interface where I can select a directory. (this I can)

After the select I would like to see the files in that directory listed and have the possibility to select a few of those files. (this I can not, how do I put the selected files in an array to work with later?)

With those selected files I want to do some actions. (this I can)

I have found a lot of stuff already, but not all of it.

Any pointer in the good direction is welcome.

thx.

The more you learn, the less you know.

Link to comment
Share on other sites

like this?

use it with the attacched file list.txt in the same directory (@scriptDir)

#include <file.au3>
#include <array.au3>
#include <GuiConstants.au3>
Opt("GUICloseOnESC", 0);turn off exit on esc.
Opt("GUIOnEventMode", 1)

Func OnExit()
    Exit
EndFunc

GuiCreate("MyGUI", 385, 269,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

Global $aRecords
If Not _FileReadToArray(@ScriptDir&"\list.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
;_ArrayDisplay($aRecords)
Global $Button[$aRecords[0]]
Global $Input[$aRecords[0]]

Global $h = 70
Global $hh = 70

For $i = 1 to $aRecords[0]
        
    $Button[$i-1] = GuiCtrlCreateButton($aRecords[$i], 50, $hh, 100, 30)
    GUICtrlSetOnEvent(-1,"display")
    
$hh = $hh+$h
Next

Func display()
    MsgBox(0,"",GUICtrlRead(@GUI_CTRLID))
EndFunc

GuiSetState()

While 1
Sleep(20)   
WEnd

list.txt

Edited by silvano
Link to comment
Share on other sites

I don't think that's what he meant. This is a set of buttons, where also not everything can be selected. The issue is described pretty clearly - he needs a list or listview which lists items, where it is possible to select multiple entries and then put the selected entries in an array on-demand.

I don't know how to enable selection of multiple items in a list or listview control, but (correct me if I'm wrong!) that seems to be what is needed here. I am not sure but I believe this has been discussed somewhere - I'll try some searching and let you know if anything comes up. But I'm not even sure it's at all possible. Maybe some of the more enlightened posters than me know?

/edit: Furthermore, Silvano: you triple-posted in this thread - for readability it might be a good idea to remove two of them...

Cheers!

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

sorry, i don't speak (and not read) english very well :)

like this?

#include <Array.au3>
#include <File.au3>
#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <string.au3>

Opt("GUICloseOnESC", 0);turn off exit on esc.
Opt("GUIOnEventMode", 1)

Func OnExit()
    Exit
EndFunc

Func esegui()
    Local $DD, $WW
    For $DD = 0 To _GUICtrlListViewGetItemCount($listview) - 1
        If _GUICtrlListViewGetCheckedState($listview, $DD) Then
            $WW = $WW + 1
        EndIf
    Next
    ; se non trovo occorrenze selezionate avviso e continuo loop
    If $WW < 1 Then
        MsgBox(0, "!", "NOT SELECTED")
    Else
        ;MsgBox(0, "!", "SELECTED!")
        GenLista($listview)
        
        ;MsgBox(0,"","Selezionati")
    EndIf
EndFunc   ;==>esegui

Func GenLista($cheLista)

    Local $MM, $PP, $RR, $n_list, $NN
    $MM = 0
    $PP = 0
    $n_list = 0
    $RR = 0
    $NN = 0

    For $PP = 0 To _GUICtrlListViewGetItemCount($cheLista) - 1
        If _GUICtrlListViewGetCheckedState($cheLista, $PP) Then
            
            Local $a_Item = _GUICtrlListViewGetItemTextArray($cheLista, $PP)
            If IsArray($a_Item) Then
                Local $totali = ""
                
                For $i = 1 To $a_Item[0]
                    $totali = $totali & $a_Item[$i] & "|" 
                    $RR = $RR + 1
                Next
                
                Global $array_split = ""
                $array_split = StringSplit(StringTrimRight($totali, 1), "|")
                _ArrayDelete($array_split, 0)
                _ArrayDisplay($array_split)
            EndIf
        EndIf
    Next
    
    Return 1
EndFunc   ;==>GenLista

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

$listview = GUICtrlCreateListView("ID|Data|", 10, 60, 200, 170, "",$LVS_EX_CHECKBOXES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

_GUICtrlListViewSetColumnWidth ($listview, 0, 80)
_GUICtrlListViewSetColumnWidth ($listview, 1, 100)
_GUICtrlListViewJustifyColumn($listview,0,2)
_GUICtrlListViewJustifyColumn($listview,1,2)

Global $aRecords
If Not _FileReadToArray(@ScriptDir&"\list.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf


For $i = 1 to $aRecords[0]
        
GUICtrlCreateListViewItem($i&"|"&$aRecords[$i], $listview)
    
Next

$Button = GuiCtrlCreateButton("selected?", 100, 250, 100, 30)
GUICtrlSetOnEvent(-1,"esegui")

GuiSetState()
While 1
Sleep(20)
WEnd
Link to comment
Share on other sites

Yup SadBunny,

that's what I mean.

sry for the triple-X, Sometimes when I post something, it takes a while for the message to be send with the result that I have multiple posts.

Ok, seems as though Silvano has given us a nice example to work with! Thanks! And good luck gertsolo :)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Try this one:

#include <GUIConstants.au3>
#include <GuiList.au3>
#include <Array.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 410, 415, 193, 115)
$Label1 = GUICtrlCreateLabel("Select Directory:", 8, 10, 82, 17)
$SelectedPath_inp = GUICtrlCreateInput("", 96, 8, 265, 21)
$Select_btn = GUICtrlCreateButton("...", 368, 6, 27, 25, 0)
$DirectoryList = GUICtrlCreateList("", 8, 48, 385, 318, BitOR($LBS_SORT,$LBS_MULTIPLESEL,$WS_BORDER))
$Ok_btn = GUICtrlCreateButton("OK", 240, 376, 75, 25, 0)
$Close_btn = GUICtrlCreateButton("Close", 320, 376, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Close_btn
            Exit
        Case $Select_btn            
            $Path = FileSelectFolder('Select Directory', '')
            GUICtrlSetData($SelectedPath_inp, $Path)
            If $Path = '' Or @error then ContinueLoop
            _GUICtrlListClear($DirectoryList)
            $ret = _GUICtrlListAddDir ($DirectoryList, 'A,H,H,RO,RW,S,NB', $Path & '\*.*')
            ConsoleWrite($Path & @CRLF)
        Case $Ok_btn
            $FileList = _GUICtrlListGetSelItemsText($DirectoryList)         
            If IsArray($FileList) Then
                If StringRight($Path, 1) = '\' Then $Path = StringTrimRight($Path, 1)
                For $i = 1 To $FileList[0]
                    $FileList[$i] = $Path & '\' & $FileList[$i]
                Next
            EndIf
            _ArrayDisplay($FileList, 'Selected Files')
    EndSwitch
WEnd

Note: The listbox display only files. If you select a folder and there are not files in the folder nothing will display.

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

  • 2 weeks later...

Good code there Danny. I am also working on a similar project for this.

The problem with that listbox is its a somewhat clumsy user interface. Normally when you have a list, you want to shift click to select a batch of items, or control to select a few at a time. If you don't have those pressed, then normally the list unselects everything except what you pressed.

Is there a standard listbox style in autoit to handle it this way, or does it require a lot more code?

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...