angel83 Posted January 10 Posted January 10 I have a problem that I can't solve, I would appreciate your help The problem is that the same names are repeated. when I search in subfolders. Example: ProgramFiles\example\folder\a1\gimp.exe ProgramFiles\example\folder\b2\gimp.exe Add the 2 executables to the ListView 1 gimp.exe 2 gimp.exe how to prevent this from happening. here is my code: expandcollapse popup#include <GuiListView.au3> #include <GUIConstants.au3> #include <WINAPI.au3> #include <misc.au3> #include <ColorConstants.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiComboBox.au3> #include <GuiConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Word.au3> Opt("GUIResizeMode", $GUI_DOCKAUTO) $hGUI = GUICreate("Test", 500, 800) GUISetBkColor(0xFFFF00) $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) $hListView = GUICtrlCreateListView("#|EXE NAME|", 34, 274, 350, 444, $iLVStyle, $iLVExtStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GuiCtrlListView_SetColumnWidth($hListView,0,35) _GuiCtrlListView_SetColumnWidth($hListView,1,290) $AddButton = GUICtrlCreateButton("Add", 122, 242, 75, 23,$WS_BORDER) $RemButton = GUICtrlCreateButton("Delete", 202, 242, 75, 23,$WS_BORDER) $RemButton3 = GUICtrlCreateButton("Delete All", 298, 242, 88, 23,$WS_BORDER) GUISetState(@SW_SHOW, $hGUI) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $AddButton REPIT() Case $RemButton _GUICtrlListView_DeleteItemsSelected($hListView) Case $RemButton3 _GUICtrlListView_DeleteAllItems($hListView) EndSwitch WEnd Func REPIT() Local $sBrowseFolder = FileSelectFolder ("Select Folder with Documents to merge", "", 4, @ScriptDir) IF @ERROR THEN Else _AddSelectFolder($sBrowseFolder) EndIf EndFunc Func _AddSelectFolder($_sFolderPath) Local $aFolderList = _FileListToArrayRec($_sFolderPath, "*exe", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT) If @error Then Return "" For $i = 1 To $aFolderList[0] GUICtrlCreateListViewItem($i & "|" & StringRegExpReplace($aFolderList[$i], "^.*\\", "") , $hListView) Next EndFunc
ioa747 Posted January 10 Posted January 10 _ArrayUnique Returns the Elements from a column of a 1D or 2D array, removing all duplicates #include <Array.au3> _ArrayUnique ( Const ByRef $aArray [, $iColumn = 0 [, $iBase = 0 [, $iCase = 0 [, $iCount = $ARRAYUNIQUE_COUNT [, $iIntType = $ARRAYUNIQUE_AUTO]]]]] ) I know that I know nothing
Solution Nine Posted January 10 Solution Posted January 10 (edited) Define an array that will hold all file names (before the GUI loop) : Global $aList[0] Replace the function with this : Func _AddSelectFolder($_sFolderPath) Local $aFolderList = _FileListToArrayRec($_sFolderPath, "*.exe", $FLTAR_FILES, $FLTAR_RECUR) If @error Then Return For $i = 1 To $aFolderList[0] $aFolderList[$i] = StringRegExpReplace($aFolderList[$i], "^.*\\", "") Next _ArrayConcatenate($aList, $aFolderList, 1) $aList = _ArrayUnique($aList, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT) _ArraySort($aList) _GUICtrlListView_DeleteAllItems($hListView) For $i = 0 To UBound($aList) - 1 GUICtrlCreateListViewItem(String($i + 1) & "|" & $aList[$i], $hListView) Next EndFunc ;==>_AddSelectFolder Edited January 10 by Nine angel83 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
angel83 Posted January 11 Author Posted January 11 It works for me. Thank you Nine much for your time in helping me. 😃👍
angel83 Posted January 11 Author Posted January 11 progress of my code. to which it would be better if we add the full path of the executable in the ListView. but save the executable in one test01.ini and full path in another test02.ini, but always load executable and full path in ListView when opening gui. test01.ini ; only the .exe executable test02.ini ; only the full path of the executable expandcollapse popup#include <GuiListView.au3> #include <GUIConstants.au3> #include <WINAPI.au3> #include <misc.au3> #include <ColorConstants.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiComboBox.au3> #include <GuiConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Word.au3> Global $aList[0] Opt("GUIResizeMode", $GUI_DOCKAUTO) $hGUI = GUICreate("Test", 1024, 800) GUISetBkColor(0xFFFF00) $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) $hListView = GUICtrlCreateListView("#|EXE NAME|ADD|", 34, 274, 850, 444, $iLVStyle, $iLVExtStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GuiCtrlListView_SetColumnWidth($hListView,0,35) _GuiCtrlListView_SetColumnWidth($hListView,1,290) _GuiCtrlListView_SetColumnWidth($hListView,2,490) $OkButton = GUICtrlCreateButton("SAVE", 42, 200, 75, 23,$WS_BORDER) $AddButton = GUICtrlCreateButton("Add", 122, 242, 75, 23,$WS_BORDER) $RemButton = GUICtrlCreateButton("Delete", 202, 242, 75, 23,$WS_BORDER) $RemButton3 = GUICtrlCreateButton("Delete All", 298, 242, 88, 23,$WS_BORDER) GUISetState(@SW_SHOW, $hGUI) _FillList(@ScriptDir & "\test01.ini") While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $msg =$OkButton $sData = "" For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1 $sData &= _GUICtrlListView_GetItemText($hListView, $i, 1) & @CRLF Next $hFile = FileOpen(@ScriptDir & "\test01.ini", 2) FileWrite($hFile, $sData) FileClose($hFile) Case $AddButton REPIT() Case $RemButton _GUICtrlListView_DeleteItemsSelected($hListView) Case $RemButton3 _GUICtrlListView_DeleteAllItems($hListView) EndSwitch WEnd Func REPIT() Local $sBrowseFolder = FileSelectFolder ("Select Folder with Documents to merge", "", 4, @ScriptDir) IF @ERROR THEN Else _AddSelectFolder($sBrowseFolder) EndIf EndFunc Func _AddSelectFolder($_sFolderPath) Local $aFolderList = _FileListToArrayRec($_sFolderPath, "*.exe", $FLTAR_FILES, $FLTAR_RECUR) If @error Then Return For $i = 1 To $aFolderList[0] $aFolderList[$i] = StringRegExpReplace($aFolderList[$i], "^.*\\", "") Next _ArrayConcatenate($aList, $aFolderList, 1) $aList = _ArrayUnique($aList, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT) _ArraySort($aList) _GUICtrlListView_DeleteAllItems($hListView) For $i = 0 To UBound($aList) - 1 GUICtrlCreateListViewItem(String($i + 1) & "|" & $aList[$i], $hListView) Next EndFunc ;==>_AddSelectFolder Func _FillList($sFile) Local $iRead = FileRead($sFile) Local $aString = StringSplit(StringStripCR($iRead), @LF) For $i = 1 To $aString[0] If $aString[$i] = "" Then ContinueLoop GUICtrlCreateListViewItem($i & "|" & StringRegExpReplace($aString[$i], "^.*\\", "") , $hListView) Next EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now