Jump to content

Need help with GUICtrlCreateRadio


Go to solution Solved by Andreik,

Recommended Posts

Hi to all

I have a task to unpack files into 2 different directories and I can’t figure out how to use the radio button to select a directory.

In this test gui i have 6 checkboxes and 6 folders

Extract to AppData\Roaming\MyFolder and 

Extract to CommonFiles\MyFolder

So i have created two GUICtrlCreateRadio buttons to select the extract location and can't figure out how to use the code with these 2 radiobuttons.

 

So I can do it without 2 radiobuttons by adding in Global $S07,  $S08,   $S09 and so on and create 12 checkboxes

For examle 6 checkboxes will extract to AppData\Roaming\MyFolder

and 6 checkboxes will Extract to CommonFiles\MyFolder.

But in that case i must use more checkboxes....

Please can you show me how to use radiobuttons in this case ?

Below is my code:

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
;=======================================
Global $S01, $S02, $S03, $S04, $S05, $S06, $RDD, $CDD
GUICreate("Small Test:", 400, 300) 
$Mylogo = @ScriptDir & "\logo.bmp"
$logo=GUICtrlCreatePic($Mylogo,0,0,400,65)
GUISetBkColor(0x00dadacc)
GUISetFont(9, 900)
$Go = GUICtrlCreateButton("Go",330,260,60,25)
GUICtrlCreateGraphic(5,75,390,2,$SS_BLACKRECT)
GUICtrlCreateGraphic(5,240,390,2,$SS_BLACKRECT)

$S01 = GUICtrlCreateCheckbox("SomeName1",10,90,300,20)
$S02 = GUICtrlCreateCheckbox("SomeName2",10,110,300,20)
$S03 = GUICtrlCreateCheckbox("SomeName3",10,130,300,20)
$S04 = GUICtrlCreateCheckbox("SomeName4",10,150,300,20)
$S05 = GUICtrlCreateCheckbox("SomeName5",10,170,300,20)
$S06 = GUICtrlCreateCheckbox("SomeName6",10,190,300,20)
$RDD = GUICtrlCreateRadio("Extract to AppData\Roaming\MyFolder",10,250,280,20)
$CDD = GUICtrlCreateRadio("Extract to CommonFiles\MyFolder",10,270,280,20)

GuiSetState()
While 1            
    $msg = guigetmsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE  
        ExitLoop    
    Case $msg = $Go     
;======================
; If ($RDD GUICtrlCreateRadio) is checked 
; It must extract to AppData\Roaming\MyFolder  
;======================        
if(GuiCtrlRead($S01) = 1) then    
DirCopy(@ScriptDir & "\Folder-1", @AppDataDir & "\MyFolder", 1)    
EndIf  
if(GuiCtrlRead($S02) = 1) then
DirCopy(@ScriptDir & "\Folder-2", @AppDataDir & "\MyFolder", 1)    
EndIf 
if(GuiCtrlRead($S03) = 1) then   
DirCopy(@ScriptDir & "\Folder-3", @AppDataDir & "\MyFolder", 1)    
EndIf 
if(GuiCtrlRead($S04) = 1) then      
DirCopy(@ScriptDir & "\Folder-4", @AppDataDir & "\MyFolder", 1)    
EndIf 
if(GuiCtrlRead($S05) = 1) then    
DirCopy(@ScriptDir & "\Folder-5", @AppDataDir & "\MyFolder", 1)    
EndIf 
if(GuiCtrlRead($S06) = 1) then     
DirCopy(@ScriptDir & "\Folder-6", @AppDataDir & "\MyFolder", 1)    
EndIf 
;======================
; If ($CDD GUICtrlCreateRadio) is checked 
; It must extract to Common Files\MyFolder  
;======================    
#RequireAdmin    
if(GuiCtrlRead($S01) = 1) then    
DirCopy(@ScriptDir & "\Folder-1", @CommonFilesDir & "\MyFolder", 1)    
EndIf 
#RequireAdmin 
if(GuiCtrlRead($S02) = 1) then
DirCopy(@ScriptDir & "\Folder-2", @CommonFilesDir & "\MyFolder", 1)    
EndIf
#RequireAdmin 
if(GuiCtrlRead($S03) = 1) then   
DirCopy(@ScriptDir & "\Folder-3", @CommonFilesDir & "\MyFolder", 1)    
EndIf
#RequireAdmin 
if(GuiCtrlRead($S04) = 1) then      
DirCopy(@ScriptDir & "\Folder-4", @CommonFilesDir & "\MyFolder", 1)    
EndIf
#RequireAdmin 
if(GuiCtrlRead($S05) = 1) then    
DirCopy(@ScriptDir & "\Folder-5", @CommonFilesDir & "\MyFolder", 1)    
EndIf 
#RequireAdmin
if(GuiCtrlRead($S06) = 1) then     
DirCopy(@ScriptDir & "\Folder-6", @CommonFilesDir & "\MyFolder", 1)    
EndIf 
;==========    
ExitLoop
EndSelect
WEnd
Exit

 

Link to comment
Share on other sites

You can do something like this:

#RequireAdmin
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Global $acCheckbox[6]
Global $asNames[6] = ['SomeName1', 'SomeName2', 'SomeName3', 'SomeName4', 'SomeName5', 'SomeName6']
Global $asPath[6] = ['Folder-1', 'Folder-2', 'Folder-3', 'Folder-4', 'Folder-5', 'Folder-6']
Global $RDD, $CDD, $sPath
GUICreate("Small Test:", 400, 300)
$Mylogo = @ScriptDir & "\logo.bmp"
$logo=GUICtrlCreatePic($Mylogo,0,0,400,65)
GUISetBkColor(0x00dadacc)
GUISetFont(9, 900)
$Go = GUICtrlCreateButton("Go",330,260,60,25)
GUICtrlCreateGraphic(5,75,390,2,$SS_BLACKRECT)
GUICtrlCreateGraphic(5,240,390,2,$SS_BLACKRECT)

For $Index = 0 To 5
    $acCheckbox[$Index] = GUICtrlCreateCheckbox($asNames[$Index],10,90 + $Index * 20,300,20)
Next
$RDD = GUICtrlCreateRadio("Extract to AppData\Roaming\MyFolder",10,250,280,20)
$CDD = GUICtrlCreateRadio("Extract to CommonFiles\MyFolder",10,270,280,20)

GuiSetState()

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Go
            If GUICtrlRead($RDD) = $GUI_CHECKED Then $sPath =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($CDD) = $GUI_CHECKED Then $sPath =  @CommonFilesDir & '\MyFolder'
            If $sPath Then
                For $Index = 0 To 5
                    If GUICtrlRead($acCheckbox[$Index]) = $GUI_CHECKED Then
                        DirCopy(@ScriptDir & '\' & $asPath[$Index], $sPath, 1)
                    EndIf
                Next
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
    EndSwitch
WEnd

 

Link to comment
Share on other sites

14 minutes ago, Andreik said:

You can do something like this:

Thank you so much!

Your code is very easy and stable than i had used before !!!

But if i will use 80 checkboxes for example i must modify the code like this ?

Global $acCheckbox[80]
Global $asNames[80] = ['SomeName1', 'SomeName2', 'SomeName3', 'SomeName4', 'SomeName5', 'SomeName6','SomeName7','SomeName8'    ;and so on]
Global $asPath[80] = ['Folder-1', 'Folder-2', 'Folder-3', 'Folder-4', 'Folder-5', 'Folder-6', 'Folder-7', 'Folder-8'    ;and so on]
Global $RDD, $CDD, $sPath

And sometimes i must use checkboxes to install, run, open or add registry keys and so on.

Can you show me how to do using each checkboxes separately one by one,

because each checkbox can be associated with diferend things, and with this lines will not be able to do that i want:

        Case $Go
            If GUICtrlRead($RDD) = $GUI_CHECKED Then $sPath =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($CDD) = $GUI_CHECKED Then $sPath =  @CommonFilesDir & '\MyFolder'
Link to comment
Share on other sites

#RequireAdmin
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
;=======================================
Global $S01, $S02, $S03, $S04, $S05, $S06, $RDD, $CDD
GUICreate("Small Test:", 400, 300)
$Mylogo = @ScriptDir & "\logo.bmp"
$logo = GUICtrlCreatePic($Mylogo, 0, 0, 400, 65)
GUISetBkColor(0x00dadacc)
GUISetFont(9, 900)
$Go = GUICtrlCreateButton("Go", 330, 260, 60, 25)
GUICtrlCreateGraphic(5, 75, 390, 2, $SS_BLACKRECT)
GUICtrlCreateGraphic(5, 240, 390, 2, $SS_BLACKRECT)

$S01 = GUICtrlCreateCheckbox("SomeName1", 10, 90, 300, 20)
$S02 = GUICtrlCreateCheckbox("SomeName2", 10, 110, 300, 20)
$S03 = GUICtrlCreateCheckbox("SomeName3", 10, 130, 300, 20)
$S04 = GUICtrlCreateCheckbox("SomeName4", 10, 150, 300, 20)
$S05 = GUICtrlCreateCheckbox("SomeName5", 10, 170, 300, 20)
$S06 = GUICtrlCreateCheckbox("SomeName6", 10, 190, 300, 20)
$RDD = GUICtrlCreateRadio("Extract to AppData\Roaming\MyFolder", 10, 250, 280, 20)
GUICtrlSetState($RDD, $GUI_CHECKED)
$CDD = GUICtrlCreateRadio("Extract to CommonFiles\MyFolder", 10, 270, 280, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Go
            ;======================
            ; If ($RDD GUICtrlCreateRadio) is checked extract to AppData\Roaming\MyFolder
            ; If ($CDD GUICtrlCreateRadio) is checked extract to Common Files\MyFolder
            ;======================
            If GUICtrlRead($RDD) = $GUI_CHECKED Then $sPath = @AppDataDir
            If GUICtrlRead($CDD) = $GUI_CHECKED Then $sPath = @CommonFilesDir

            If GUICtrlRead($S01) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-1", $sPath & "\" & GUICtrlRead($S01, 1), 1)
            If GUICtrlRead($S02) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-2", $sPath & "\" & GUICtrlRead($S02, 1), 1)
            If GUICtrlRead($S03) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-3", $sPath & "\" & GUICtrlRead($S03, 1), 1)
            If GUICtrlRead($S04) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-4", $sPath & "\" & GUICtrlRead($S04, 1), 1)
            If GUICtrlRead($S05) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-5", $sPath & "\" & GUICtrlRead($S04, 1), 1)
            If GUICtrlRead($S06) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-6", $sPath & "\" & GUICtrlRead($S06, 1), 1)

            ExitLoop
    EndSelect
WEnd

Exit

 

Edited by ioa747
corection

I know that I know nothing

Link to comment
Share on other sites

Posted (edited)

Thank you guys so much for your help,

without your support I would not have been able to achieve a positive result.

ioa747

Your code looks very good but It doesn't work for me..
 

2 hours ago, Nine said:

You could use ternary (single line) :

If GuiCtrlRead($S01) = 1 Then DirCopy(@ScriptDir & "\Folder-1", (GuiCtrlRead($RDD) = 1 ? @AppDataDir : @CommonFilesDir) & "\MyFolder", 1)

Yes it works but when i add below each line the "EndIf" i got error.

 

Andreik

Your code works fine as i wanted but the problem i can't add more checkboxes.

I will try to modify it...

 

 

Edited by Antivoyager
Link to comment
Share on other sites

44 minutes ago, Antivoyager said:

Andreik

Your code works fine as i wanted but the problem i can't add more checkboxes.

I will try to modify it...

Try to modify the script to fit your needs and if you need further help just let me know more details.

Edit: made an example for you with dynamic number of folders

#include <GUIConstantsEx.au3>

Global $sPath
Global $iFolders = 100      ; Change this as you want
Global $asFolder[$iFolders], $asPath[$iFolders], $acCtrl[$iFolders]
Global $iCols = Int($iFolders / 10) + (Mod($iFolders, 10) ? 1 : 0)
Global $iColWidth = 120
Global $iWidth = ($iCols * $iColWidth < 500 ? 500 : $iCols * $iColWidth)

; Generate some fake data but this can be read from a file, a database or other methods
For $Index = 0 To $iFolders - 1
    $asFolder[$Index] = 'Folder ' & ($Index + 1)
    $asPath[$Index] = @ScriptDir & '\Folder ' & ($Index + 1)
Next

$hGUI = GUICreate('Test', $iWidth, 400)
For $Index = 0 To $iFolders - 1
    $acCtrl[$Index] = GUICtrlCreateCheckbox($asFolder[$Index], Int($Index / 10) * 120 + 10, Mod($Index, 10) * 30 + 10, $iColWidth - 20, 20)
Next
GUICtrlCreateGroup('Destination', 10, 310, 300, 80)
$cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20)
$cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$cExtract = GUICtrlCreateButton('Extract', $iWidth - 150, 350, 140, 40)
GUISetState(@SW_SHOW, $hGUI)

While True
    Switch GUIGetMsg()
        Case $cExtract
            If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sPath =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sPath =  @CommonFilesDir & '\MyFolder'
            If $sPath Then
                For $Index = 0 To $iFolders - 1
                    If GUICtrlRead($acCtrl[$Index]) = $GUI_CHECKED Then
                        ConsoleWrite($asFolder[$Index] & '   --->>>   ' & $sPath & @CRLF)
;~                         DirCopy($asPath[$Index], $sPath, 1)
                    EndIf
                Next
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Andreik
Link to comment
Share on other sites

23 minutes ago, Andreik said:

Try to modify the script to fit your needs and if you need further help just let me know more details.

Thank you!

So i tried to make 25 checkboxes and it seems to work.

#RequireAdmin
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Global $acCheckbox[25]
Global $asNames[25] = ['Name1', 'Name2', 'Name3', 'Name4', 'Name5', 'Name6', 'Name7', 'Name8', 'Name9', 'Name10', 'Name11', 'Name12', 'Name13', 'Name14', 'Name15', 'Name16', 'Name17', 'Name18', 'Name19', 'Name20', 'Name21', 'Name22', 'Name23', 'Name24', 'Name25']
Global $asPath[25] = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25']
Global $RDD, $CDD, $sPath
GUICreate("Small Test:", 600, 620)
$Go = GUICtrlCreateButton("Go", 250, 580, 100, 25)
GUICtrlCreateGraphic(2, 40, 596, 2, $SS_BLACKRECT)
GUICtrlCreateGraphic(2, 565, 596, 2, $SS_BLACKRECT)
$hlabel = GUICtrlCreateLabel("My Setup", 260,10,300,20)
GUICtrlSetColor(-1, 0xf20c00) 
GUICtrlSetFont($hlabel, 14, 900)

For $Index = 0 To 24
    $acCheckbox[$Index] = GUICtrlCreateCheckbox($asNames[$Index],10,50 + $Index * 20,300,20)
Next
$RDD = GUICtrlCreateRadio("Roaming DIR",10,570,200,20)
$CDD = GUICtrlCreateRadio("CommonFiles DIR",10,590,200,20)

GuiSetState()

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Go
            If GUICtrlRead($RDD) = $GUI_CHECKED Then $sPath =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($CDD) = $GUI_CHECKED Then $sPath =  @CommonFilesDir & '\MyFolder'
            If $sPath Then
                For $Index = 0 To 24
                    If GUICtrlRead($acCheckbox[$Index]) = $GUI_CHECKED Then
                        DirCopy(@ScriptDir & '\' & $asPath[$Index], $sPath, 1)
                    EndIf
                Next
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
    EndSwitch
WEnd

Is this possible add to global patches and names to continue create checkboxes ?

If so how can i add to left side the next columns to have more checkboxes ?

Link to comment
Share on other sites

Here is a real case of the previous example without fake data. It will display all directories from windows:

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

; Change @WindowsDir with whatever path do you want
Global $aFile = _FileListToArray(@WindowsDir, Default, $FLTA_FOLDERS, True)
If Not IsArray($aFile) Then Exit

Global $sPath
Global $iFolders = $aFile[0]
Global $asFolder[$iFolders], $asPath[$iFolders], $acCtrl[$iFolders]
Global $iCols = Int($iFolders / 10) + (Mod($iFolders, 10) ? 1 : 0)
Global $iColWidth = 120
Global $iWidth = ($iCols * $iColWidth < 500 ? 500 : $iCols * $iColWidth)
Global $sDrive, $sDir, $sFileName, $sExtension

For $Index = 0 To $iFolders - 1
    _PathSplit($aFile[$Index + 1], $sDrive, $sDir, $sFileName, $sExtension)
    $asFolder[$Index] = $sFileName
    $asPath[$Index] = $aFile[$Index + 1]    ; This is kinda redundant but used for the sake of symmetry with the previous example
Next

$hGUI = GUICreate('Test', $iWidth, 400)
For $Index = 0 To $iFolders - 1
    $acCtrl[$Index] = GUICtrlCreateCheckbox($asFolder[$Index], Int($Index / 10) * 120 + 10, Mod($Index, 10) * 30 + 10, $iColWidth - 20, 20)
Next
GUICtrlCreateGroup('Destination', 10, 310, 300, 80)
$cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20)
$cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$cExtract = GUICtrlCreateButton('Extract', $iWidth - 150, 350, 140, 40)
GUISetState(@SW_SHOW, $hGUI)

While True
    Switch GUIGetMsg()
        Case $cExtract
            If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sPath =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sPath =  @CommonFilesDir & '\MyFolder'
            If $sPath Then
                For $Index = 0 To $iFolders - 1
                    If GUICtrlRead($acCtrl[$Index]) = $GUI_CHECKED Then
                        ConsoleWrite($asPath[$Index] & '   --->>>   ' & $sPath & @CRLF)
;~                         DirCopy($asPath[$Index], $sPath, 1)
                    EndIf
                Next
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

PS: don't run it with DirCopy() uncommented because it will copy the content of windows directory to selected destination.

If you have way more items than could fit nicely in your window you might consider using a listview with checkboxes.

Edited by Andreik
Link to comment
Share on other sites

Posted (edited)
19 minutes ago, Andreik said:

Here is a real case of the previous example without fake data. It will display all directories from windows:

Its very good - exactly what i wanted!

I need only as working folder is @ScriptDir,  nothing else

I have Changed to Global $aFile = _FileListToArray(@ScriptDir, Default, $FLTA_FOLDERS, True) ; I am right ?

Is it possible to hide folders  with "_"  an underscore ("_somefolder" for example) from @ScriptDir ? 

sometimes i need to keep some files into working folder as .bmp  .txt and so on...

Everything else is great !

Thank you!

 

Edited by Antivoyager
Link to comment
Share on other sites

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

; Change @WindowsDir with whatever path do you want
Global $aFile = _FileListToArray(@DesktopDir, Default, $FLTA_FOLDERS, True)
If Not IsArray($aFile) Then Exit

Global $sDrive, $sDir, $sFileName, $sExtension

; Remove directories that starts with an underscore
Global $sFiles = ''
For $Index = 1 To $aFile[0]
    _PathSplit($aFile[$Index], $sDrive, $sDir, $sFileName, $sExtension)
    $sFiles &=  (StringLeft($sFileName, 1) <> '_' ? $aFile[$Index] & '|' : '')
Next
$aFile = StringSplit(StringTrimRight($sFiles, 1), '|')

Global $sPath
Global $iFolders = $aFile[0]
Global $asFolder[$iFolders], $asPath[$iFolders], $acCtrl[$iFolders]
Global $iCols = Int($iFolders / 10) + (Mod($iFolders, 10) ? 1 : 0)
Global $iColWidth = 120
Global $iWidth = ($iCols * $iColWidth < 500 ? 500 : $iCols * $iColWidth)

For $Index = 0 To $iFolders - 1
    _PathSplit($aFile[$Index + 1], $sDrive, $sDir, $sFileName, $sExtension)
    $asFolder[$Index] = $sFileName
    $asPath[$Index] = $aFile[$Index + 1]    ; This is kinda redundant but used for the sake of symmetry with the previous example
Next

$hGUI = GUICreate('Test', $iWidth, 400)
For $Index = 0 To $iFolders - 1
    $acCtrl[$Index] = GUICtrlCreateCheckbox($asFolder[$Index], Int($Index / 10) * 120 + 10, Mod($Index, 10) * 30 + 10, $iColWidth - 20, 20)
Next
GUICtrlCreateGroup('Destination', 10, 310, 300, 80)
$cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20)
$cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$cExtract = GUICtrlCreateButton('Extract', $iWidth - 150, 350, 140, 40)
GUISetState(@SW_SHOW, $hGUI)

While True
    Switch GUIGetMsg()
        Case $cExtract
            If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sPath =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sPath =  @CommonFilesDir & '\MyFolder'
            If $sPath Then
                For $Index = 0 To $iFolders - 1
                    If GUICtrlRead($acCtrl[$Index]) = $GUI_CHECKED Then
                        ; ConsoleWrite($asPath[$Index] & '   --->>>   ' & $sPath & @CRLF)
                        DirCopy($asPath[$Index], $sPath, 1)
                    EndIf
                Next
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

This would be a more elegant solution using a listview. This can be suitable if you have many items to display.

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

Global $sSourceDir = @DesktopDir
Global $sDestinationDir

Global $hGUI, $cList, $cAppData, $cCommonFiles, $cExtract

Global $aFile = _FileListToArray($sSourceDir, Default, $FLTA_FOLDERS, False)
If Not IsArray($aFile) Then Exit

$hGUI = GUICreate('Test', 800, 400)
$cList = GUICtrlCreateListView('Path', 10, 10, 780, 290, BitOR($LVS_SMALLICON, $WS_DLGFRAME, $LVS_NOCOLUMNHEADER), $LVS_EX_CHECKBOXES)
GUICtrlCreateGroup('Destination', 10, 310, 300, 80)
$cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20)
$cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$cExtract = GUICtrlCreateButton('Extract', 650, 350, 140, 40)
_GUICtrlListView_BeginUpdate($cList)
For $Index = 1 To $aFile[0]
    If StringLeft($aFile[$Index], 1) = '_' Then ContinueLoop
    GUICtrlCreateListViewItem($aFile[$Index], $cList)
Next
_GUICtrlListView_EndUpdate($cList)
_GUICtrlListView_SetColumnWidth($cList, 0, 300)
GUISetState(@SW_SHOW, $hGUI)

While True
    Switch GUIGetMsg()
        Case $cExtract
            If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sDestinationDir =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sDestinationDir =  @CommonFilesDir & '\MyFolder'
            If $sDestinationDir Then
                For $Index = 0 To _GUICtrlListView_GetItemCount($cList) - 1
                    If _GUICtrlListView_GetItemChecked($cList, $Index) Then
                        ; ConsoleWrite($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index) & '   --->>>   ' & $sDestinationDir & @CRLF)
                        DirCopy($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index), $sDestinationDir, 1)
                    EndIf
                Next
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Andreik
Link to comment
Share on other sites

Posted (edited)

Unfortunately it doesn't work. Doesn't copy anything. I don't know why.
The GUI is beautiful and suits me 100%.

 

Before i used like this:

DirCopy(@ScriptDir & "\surcefodername", @AppDataDir & "\destfoldername", 1)

and it worked perfectly

;===========

I can't figure out how and where to use DirCopy

Edited by Antivoyager
Link to comment
Share on other sites

I gave you an example without actual copying the directories. Replace ConsoleWrite() with DirCopy(). I updated previous examples to copy the directories.

Edited by Andreik
Link to comment
Share on other sites

27 minutes ago, Andreik said:

I gave you an example without actual copying the directories. Replace ConsoleWrite() with DirCopy(). I updated previous examples to copy the directories.

Fixed, thanks!

So, the last question, after extracting each checkbox, how to add - something like this:

    SplashTextOn('', ' (foldername) successfully extracted !', 300, 100)
    Sleep(1000)
    SplashOff()

 

And close the GUI after finished..

Link to comment
Share on other sites

  • Solution
Posted (edited)

Exactly as you said:

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

Global $sSourceDir = @DesktopDir
Global $sDestinationDir

Global $hGUI, $cList, $cAppData, $cCommonFiles, $cExtract

Global $aFile = _FileListToArray($sSourceDir, Default, $FLTA_FOLDERS, False)
If Not IsArray($aFile) Then Exit

$hGUI = GUICreate('Test', 800, 400)
$cList = GUICtrlCreateListView('Path', 10, 10, 780, 290, BitOR($LVS_SMALLICON, $WS_DLGFRAME, $LVS_NOCOLUMNHEADER), $LVS_EX_CHECKBOXES)
GUICtrlCreateGroup('Destination', 10, 310, 300, 80)
$cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20)
$cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$cExtract = GUICtrlCreateButton('Extract', 650, 350, 140, 40)
_GUICtrlListView_BeginUpdate($cList)
For $Index = 1 To $aFile[0]
    If StringLeft($aFile[$Index], 1) = '_' Then ContinueLoop
    GUICtrlCreateListViewItem($aFile[$Index], $cList)
Next
_GUICtrlListView_EndUpdate($cList)
_GUICtrlListView_SetColumnWidth($cList, 0, 300)
GUISetState(@SW_SHOW, $hGUI)

While True
    Switch GUIGetMsg()
        Case $cExtract
            If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sDestinationDir =  @AppDataDir & '\MyFolder'
            If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sDestinationDir =  @CommonFilesDir & '\MyFolder'
            If $sDestinationDir Then
                For $Index = 0 To _GUICtrlListView_GetItemCount($cList) - 1
                    If _GUICtrlListView_GetItemChecked($cList, $Index) Then
                        DirCopy($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index), $sDestinationDir, 1)
                        SplashTextOn('', _GUICtrlListView_GetItemText($cList, $Index) & ' successfully extracted !', 300, 100)
                        Sleep(1000)
                        SplashOff()
                    EndIf
                Next
                Exit
            Else
                MsgBox(0x10, 'Error', 'Please select the extraction directory')
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

In my opinion would be more nice to display this splash before starting the copy process and close it when it's done without any pause in the script.

If _GUICtrlListView_GetItemChecked($cList, $Index) Then
    SplashTextOn('', 'Extracting ' & _GUICtrlListView_GetItemText($cList, $Index), 300, 100)
    DirCopy($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index), $sDestinationDir, 1)
    SplashOff()
EndIf

 

Edited by Andreik
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...