Jump to content

Deleting file from list (HELP)


Guest AX5
 Share

Recommended Posts

Can understand how do select a file from list the you can press Delete to remove the file from list

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Demo Manager", 427, 296, 231, 155)
$Button1 = GUICtrlCreateButton("Choose a folder", 272, 110, 113, 33, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Move", 272, 168, 113, 33, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Remove", 272, 208, 113, 33, $WS_GROUP)
$Label1 = GUICtrlCreateLabel(" File Display", 115, 52, 60, 15)
$List1 = GUICtrlCreateList("Files will Display here", 32, 72, 225, 201)
$Pic1 = GUICtrlCreatePic("img/", 0, 0, 427, 296, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            List_Folder_Contents()

        Case $Button3

        Case $Button4
            GUICtrlListView_DeleteItemsSelected()
    EndSwitch
WEnd

Func List_Folder_Contents()

    ; Choose folder
    $sFolderPath = FileSelectFolder("Choose a folder", "M:\")
    If $sFolderPath = "" Then Return ; No folder chosen
    ; Clear list
    GUICtrlSetData($List1, "|")
    ; List contents into array
    $aFile_Array = _FileListToArray($sFolderPath, "*", 1)
    ; If no files found
    If @error Then
        GUICtrlSetData($List1, "|No files found!")
        Return
    EndIf
    ; Move found files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc

Func GUICtrlListView_DeleteItemsSelected()

    $List1 = $List1
    _GUICtrlListView_SetItemSelected($List1, Random(0, UBound($aItems) - 1, 1))

EndFunc
Link to comment
Share on other sites

Use _GUICtrlListView_GetSelectedIndices to get a list of selected indices.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

AX5,

You cannot use the _GUICtrlListView functions on List controls - as the name suggests they only work on ListView controls. :D

This should do what you want:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $aFile_Array[1]

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Demo Manager", 427, 296, 231, 155)
$Button1 = GUICtrlCreateButton("Choose a folder", 272, 110, 113, 33, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Move", 272, 168, 113, 33, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Remove", 272, 208, 113, 33, $WS_GROUP)
$Label1 = GUICtrlCreateLabel(" File Display", 115, 52, 60, 15)
$List1 = GUICtrlCreateList("Files will Display here", 32, 72, 225, 201)
$Pic1 = GUICtrlCreatePic("img/", 0, 0, 427, 296, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            List_Folder_Contents()

        Case $Button3

        Case $Button4
            DeleteFromList()
    EndSwitch
WEnd

Func List_Folder_Contents()

    ; Choose folder
    $sFolderPath = FileSelectFolder("Choose a folder", "M:\")
    If $sFolderPath = "" Then Return ; No folder chosen
    ; Clear list
    GUICtrlSetData($List1, "|")
    ; List contents into array
    $aFile_Array = _FileListToArray($sFolderPath, "*", 1)
    ; If no files found
    If @error Then
        GUICtrlSetData($List1, "|No files found!")
        Return
    EndIf
    ; Move found files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc

Func DeleteFromList()

    ; Find index of selected file
    $iIndex = _ArraySearch($aFile_Array, GUICtrlRead($List1))
    If Not @Error Then
        ; Delete from array and adjust count
        _ArrayDelete($aFile_Array, $iIndex)
        $aFile_Array[0] -= 1
    EndIf
    ; Empty list
    GUICtrlSetData($List1, "")
    ; Put remaining files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

AX5,

You cannot use the _GUICtrlListView functions on List controls - as the name suggests they only work on ListView controls. :D

This should do what you want:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $aFile_Array[1]

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Demo Manager", 427, 296, 231, 155)
$Button1 = GUICtrlCreateButton("Choose a folder", 272, 110, 113, 33, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Move", 272, 168, 113, 33, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Remove", 272, 208, 113, 33, $WS_GROUP)
$Label1 = GUICtrlCreateLabel(" File Display", 115, 52, 60, 15)
$List1 = GUICtrlCreateList("Files will Display here", 32, 72, 225, 201)
$Pic1 = GUICtrlCreatePic("img/", 0, 0, 427, 296, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            List_Folder_Contents()

        Case $Button3

        Case $Button4
            DeleteFromList()
    EndSwitch
WEnd

Func List_Folder_Contents()

    ; Choose folder
    $sFolderPath = FileSelectFolder("Choose a folder", "M:\")
    If $sFolderPath = "" Then Return ; No folder chosen
    ; Clear list
    GUICtrlSetData($List1, "|")
    ; List contents into array
    $aFile_Array = _FileListToArray($sFolderPath, "*", 1)
    ; If no files found
    If @error Then
        GUICtrlSetData($List1, "|No files found!")
        Return
    EndIf
    ; Move found files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc

Func DeleteFromList()

    ; Find index of selected file
    $iIndex = _ArraySearch($aFile_Array, GUICtrlRead($List1))
    If Not @Error Then
        ; Delete from array and adjust count
        _ArrayDelete($aFile_Array, $iIndex)
        $aFile_Array[0] -= 1
    EndIf
    ; Empty list
    GUICtrlSetData($List1, "")
    ; Put remaining files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc

M23

Thx man but the file dos not remove in the Folder only on the list

Link to comment
Share on other sites

  • Moderators

AX5,

but the file dos not remove in the Folder only on the list

But that is what you asked for! :

you can press Delete to remove the file from list

Seriously, to delete the file, use FileDelete . You already have $sFolderPath and by adjusting the first few lines of the DeleteFromList() function like this:

; Get name of selected file
   $sFileName = GUICtrlRead($List1)
   ; Find index of selected file
   $iIndex = _ArraySearch($aFile_Array, $sFileName)

you have the name as well. What more do you need?

Could I suggest using FileRecycle (at least at first) to keep the safety net of the Recycle Bin. You would not want to permanently delete something important, would you! :D

Over to you! :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Omg im confused

Is this right ?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $aFile_Array[1]

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Demo Manager", 427, 296, 231, 155)
$Button1 = GUICtrlCreateButton("Choose a folder", 272, 110, 113, 33, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Move", 272, 168, 113, 33, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Remove", 272, 208, 113, 33, $WS_GROUP)
$Label1 = GUICtrlCreateLabel(" File Display", 115, 52, 60, 15)
$List1 = GUICtrlCreateList("Files will Display here", 32, 72, 225, 201)
$Pic1 = GUICtrlCreatePic("img/", 0, 0, 427, 296, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            List_Folder_Contents()

        Case $Button3

        Case $Button4
            DeleteFromList()
    EndSwitch
WEnd

Func List_Folder_Contents()

    ; Choose folder
    $sFolderPath = FileSelectFolder("Choose a folder", "M:\")
    If $sFolderPath = "" Then Return ; No folder chosen
    ; Clear list
    GUICtrlSetData($List1, "|")
    ; List contents into array
    $aFile_Array = _FileListToArray($sFolderPath, "*", 1)
    ; If no files found
    If @error Then
        GUICtrlSetData($List1, "|No files found!")
        Return
    EndIf
    ; Move found files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc

Func DeleteFromList()
$sFileName = GUICtrlRead($List1)
    ; Find index of selected file
    $iIndex = _ArraySearch($aFile_Array, $sFileName)
    If Not @Error Then
        ; Delete from array and adjust count
        _ArrayDelete($aFile_Array, $iIndex)
        $aFile_Array[0] -= 1
    EndIf
    ; Empty list
    GUICtrlSetData($List1, "")
    ; Put remaining files into list
    For $i = 1 To $aFile_Array[0]
        GUICtrlSetData($List1, $aFile_Array[$i])
    Next

EndFunc
Edited by AX5
Link to comment
Share on other sites

  • Moderators

AX5,

Well, you now have $FolderPath and $sFileName - so you can identify the file to be deleted. :huggles:

Have you looked at FileDelete or FileRecycle in the Help file to see how to use them? How do you think the 2 variables might fit into the commands?

Come on, start doing some of this yourself! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

AX5,

Good for you! :D

23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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