Page 1 of 1

help with get list in checkboxs

Posted: 09 May 2018, 07:06
by Tomer
Hye,

in the sample code below i get a list only in one checkbox for all the folders\files found,
i need help to get the list of each folder\file in separately checkbox.

thanks in advance!

Code: Select all

vDir1 := "C:"
vList := ""
CSize := 0

; folders
foldersBlacklist := "Windows,Users,$Recycle.Bin,Program Files,Program Files (x86),ProgramData"
excludedFolders := ""

; files
filesExtBlacklist := "log,sys,cmd,bat,bak,ini,txt,dll,err,db"
filesBlacklist := "bootmgr,kk1.exe,pv.exe,Uninstal.exe"
excludedFiles := ""

Loop, Files, % vDir1 "\*", D ; folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
}

Loop, Files, % vDir1 "\*", F ; files
{
	if A_LoopFileExt in %filesExtBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	if A_LoopFileName in %filesBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
	CSize += A_LoopFileSize ; count in c:\ root only
}

vList := SubStr(vList, 1, -1)
listC := % StrReplace(vList, "|", "`n")

Loop, Parse, vList, |
	Loop, Files, % A_LoopField "\*", FR
			CSize += A_LoopFileSize ; count in c:\ folders



;~ MsgBox, % StrReplace(vList, "|", "`n") ; show white list
;~ MsgBox, % StrReplace(excludedFolders, (vDir1 . "\"), "") ; show foldersBlacklist
;~ MsgBox, % StrReplace(excludedFiles, (vDir1 . "\"), "") ; show filesExtBlacklist & filesBlacklist



Gui Add, Checkbox, vResotreChoice, % StrReplace(vList, "|", "`n")
Gui Show



Re: help with get list in checkboxs

Posted: 10 May 2018, 04:41
by Tomer
.

Re: help with get list in checkboxs

Posted: 10 May 2018, 04:54
by jeeswg
If you want to use a ComboBox/ListBox, perhaps this:
StrReplace(vList, "|", "`n")
should be this:
StrReplace(vList, "`n", "|")

Or you need to do a loop (Loop Parse) and create a checkbox for each item via Gui Add.

I'm not sure what the best control is for a list where each item has a checkbox. Maybe ComboBox/ListBox/listview.

Re: help with get list in checkboxs

Posted: 10 May 2018, 05:18
by Tomer
thanks jeeswg,
i considering to use ListBox if its easier method,
my qusetsion is if i can get a variable for each selected item from the outcome ListBox ?
and if its possible to select more then one item from the ListBox (e.x holding ctrl & left click) ?

Thanks

Code: Select all

vDir1 := "C:"
vList := ""
CSize := 0

; folders
foldersBlacklist := "Windows,Users,$Recycle.Bin,Program Files,Program Files (x86),ProgramData"
excludedFolders := ""

; files
filesExtBlacklist := "log,sys,cmd,bat,bak,ini,txt,dll,err,db"
filesBlacklist := "bootmgr,kk1.exe,pv.exe,Uninstal.exe"
excludedFiles := ""

Loop, Files, % vDir1 "\*", D ; folders
{
	if A_LoopFileName in %foldersBlacklist%
	{
		excludedFolders .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
}

Loop, Files, % vDir1 "\*", F ; files
{
	if A_LoopFileExt in %filesExtBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	if A_LoopFileName in %filesBlacklist%
	{
		excludedFiles .= """" . A_LoopFileFullPath . """ "
		continue
	}
	
	vList .= A_LoopFileFullPath . "|"
	CSize += A_LoopFileSize ; count in c:\ root only
}


Gui Add, ListBox,h500 w500, % StrReplace(vList, "`n", "|")
Gui Show



Re: help with get list in checkboxs

Posted: 16 May 2018, 05:06
by Tomer
up

Re: help with get list in checkboxs

Posted: 16 May 2018, 10:54
by wolf_II
Try replacing ListBox with ListView, as suggested by jeeswg, like so:

Replace this:

Code: Select all

Gui, Add, ListBox,h500 w500, % StrReplace(vList, "`n", "|")
with this:

Code: Select all

Gui Add, ListView, h500 w500 Checked, Path
For each, file in % StrSplit(vList, "|")
    LV_Add(, file)
I hope that helps.

Re: help with get list in checkboxs

Posted: 16 May 2018, 11:06
by Tomer
Thanks Wolf!
Ill try it and update later.

Re: help with get list in checkboxs

Posted: 16 May 2018, 11:21
by wolf_II
The top row of ListView only contains text, and it's not needed here.
To not display the header row, use this: -Hdr

Code: Select all

Gui Add, ListView, h500 w500 Checked -Hdr, FileFullPath
For each, file in % StrSplit(RTrim(vList, "|"), "|")
    LV_Add(, file)
Gui Show
I also used RTrim() on vList.

Re: help with get list in checkboxs

Posted: 16 May 2018, 13:54
by jeeswg
Here's an example of a listview control with checkboxes. You can use space to toggle the checked state of an item.

Code: Select all

;listview control with checkboxes

Gui, New, +HwndhGui, MyWinTitle
Gui, Add, ListView, r3 +Checked, LVH 1|LVH 2|LVH 3
Loop, 3
	if (A_Index = 1)
		LV_Add("Select", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
	else
		LV_Add("", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
Gui, Show, w300 h300
return

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

q:: ;get checkbox states
ControlGet, hCtl, Hwnd,, SysListView321, % "ahk_id " hGui
SendMessage, 0x1004, 0, 0,, % "ahk_id " hCtl ;LVM_GETITEMCOUNT := 0x1004
vCount := ErrorLevel
vOutput := ""
Loop, % vCount
{
	;LVIS_STATEIMAGEMASK := 0xF000
	SendMessage, 0x102C, % A_Index-1, 0xF000,, % "ahk_id " hCtl ;LVM_GETITEMSTATE := 0x102C
	vIsChecked := (ErrorLevel >> 12) - 1
	vOutput .= (A_Index=1?"":" ") vIsChecked
}
MsgBox, % vOutput
return

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

GuiClose:
ExitApp
return

Re: help with get list in checkboxs

Posted: 17 May 2018, 03:08
by Tomer
thank you very much wolf and jeeswg!!
works good!!