Jump to content

Recommended Posts

Posted

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:

#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

 

Posted

_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
Posted (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 by Nine
Posted

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

#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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...