Jump to content

how to delet file from listview


aness07
 Share

Recommended Posts

Hi..

I have create a script to get files form folder

I have make a button to remove a file from listview

how can i do it pleas help me

this is the script ..

#include
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("show file from folder", 453, 340, 192, 124)
$ListView1 = GUICtrlCreateListView("File name|Attribute|Track", 8, 8, 442, 294)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 125)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150)
$BDeleteFile = GUICtrlCreateButton("Delete file", 328, 304, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;~ -----------------------------------------------
$DIR = "E:aness"
;~ get the file inot array
$FILE = _FileListToArray($DIR,"*")

Func ShowFils()
sleep(500)
For $INDEX = 1 To $FILE[0]
     $POINT = StringInStr($FILE[$INDEX],".",0,-1)
    
;~     if there are an error or searching file end ExitLoop
    If @error Then ExitLoop
;~        get the attrib of file
      $att = FileGetAttrib($DIR& ""&$FILE[$INDEX])
;~       checking about the attrib of file
      $check_att = StringInStr($att,"H")
;~          if stringinstr Returned True
       
            if $check_att <> 0 Then
               
                           If $POINT <> 0 Then
                     ;~ adding the hidden  to liswiew
        
                  GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)
                EndIf              
      Else
               If $POINT <> 0 Then
    
                    ;~ adding the view  to liswiew
                  GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Not Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)
    
               EndIf
     EndIf
Next
EndFunc

;~ ----------------------------------------------------
ShowFils()
;~ -------------------------------------------------------

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case
            $BDeleteFile
;~             what It should to do
    EndSwitch
WEnd

this is my example..

thank you

Edited by aness07
Link to comment
Share on other sites

maybe so.

#include <array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("show file from folder", 453, 340, 192, 124)
$ListView1 = GUICtrlCreateListView("File name|Attribute|Track", 8, 8, 442, 294)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 125)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150)
$BDeleteFile = GUICtrlCreateButton("Delete file", 328, 304, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;~ -----------------------------------------------
$DIR = "C:Program Files"
;~ get the file inot array
$FILE = _FileListToArray($DIR,"*")

Func ShowFils()
sleep(500)
For $INDEX = 1 To $FILE[0]
$POINT = StringInStr($FILE[$INDEX],".",0,-1)

;~ if there are an error or searching file end ExitLoop
If @error Then ExitLoop
;~ get the attrib of file
$att = FileGetAttrib($DIR& ""&$FILE[$INDEX])
;~ checking about the attrib of file
$check_att = StringInStr($att,"H")
;~ if stringinstr Returned True

if $check_att <> 0 Then

If $POINT <> 0 Then
;~ adding the hidden to liswiew

GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)
EndIf
Else
If $POINT <> 0 Then

;~ adding the view to liswiew
GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Not Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)

EndIf
EndIf
Next
EndFunc

;~ ----------------------------------------------------
ShowFils()
;~ -------------------------------------------------------

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $BDeleteFile
$path=_GUICtrlListView_GetItemText($ListView1, 0,2)
msgbox(0,"",$path) ; show the path to del on msgbox
;FileDelete($path) use to delete

EndSwitch
WEnd
Edited by Danyfirex
Link to comment
Share on other sites

mmm Try this.

#include <array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("show file from folder", 453, 340, 192, 124)
$ListView1 = GUICtrlCreateListView("File name|Attribute|Track", 8, 8, 442, 294)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 125)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150)
$BDeleteFile = GUICtrlCreateButton("Delete file", 328, 304, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;~ -----------------------------------------------
$DIR = "C:"
;~ get the file inot array
$FILE = _FileListToArray($DIR,"*")

Func ShowFils()
sleep(500)
For $INDEX = 1 To $FILE[0]
$POINT = StringInStr($FILE[$INDEX],".",0,-1)

;~ if there are an error or searching file end ExitLoop
If @error Then ExitLoop
;~ get the attrib of file
$att = FileGetAttrib($DIR& ""&$FILE[$INDEX])
;~ checking about the attrib of file
$check_att = StringInStr($att,"H")
;~ if stringinstr Returned True

if $check_att <> 0 Then

If $POINT <> 0 Then
;~ adding the hidden to liswiew

GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)
EndIf
Else
If $POINT <> 0 Then

;~ adding the view to liswiew
GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Not Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)

EndIf
EndIf
Next
EndFunc

;~ ----------------------------------------------------
ShowFils()
;~ -------------------------------------------------------

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $BDeleteFile
$path= _GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),2)
msgbox(0,"",$path) ; show the path to del on msgbox
;FileDelete($path) use to delete

EndSwitch
WEnd
Link to comment
Share on other sites

Link to comment
Share on other sites

Can one of you explain how this works on the user's side? Do they click to choose the file that they want to delete? I'm looking to do something similar, but would like the event to open the directory and its contents within.

maybe you should create a new topic.

try this.

#include <array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiListView.au3>#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("show file from folder", 453, 340, 192, 124)
$ListView1 = GUICtrlCreateListView("File name|Attribute|Track", 8, 8, 442, 294)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 125)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150)
$BDeleteFile = GUICtrlCreateButton("Delete file", 328, 304, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;~ -----------------------------------------------
$DIR = "C:windows"
;~ get the file inot array
$FILE = _FileListToArray($DIR,"*")

Func ShowFils()
sleep(500)
For $INDEX = 1 To $FILE[0]
$POINT = StringInStr($FILE[$INDEX],".",0,-1)

;~ if there are an error or searching file end ExitLoop
If @error Then ExitLoop
;~ get the attrib of file
$att = FileGetAttrib($DIR& ""&$FILE[$INDEX])
;~ checking about the attrib of file
$check_att = StringInStr($att,"H")
;~ if stringinstr Returned True

if $check_att <> 0 Then

If $POINT <> 0 Then
;~ adding the hidden to liswiew

GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)
EndIf
Else
If $POINT <> 0 Then

;~ adding the view to liswiew
GUICtrlCreateListViewItem($FILE[$INDEX] & "|" & "Not Hidden"&"|"&$DIR&""&$FILE[$INDEX],$ListView1)

EndIf
EndIf
Next
EndFunc

;~ ----------------------------------------------------
ShowFils()
;~ -------------------------------------------------------

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $BDeleteFile
local $path= _GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),2)
ShellExecute($path)
$path=dir($path)
Run("Explorer " & $path)
;msgbox(0,"",$path) ; show the path to del on msgbox
;FileDelete($path) use to delete

EndSwitch
WEnd


func dir($path)
local $delimiter=""
$array =StringSplit($path,$delimiter)
$len=UBound($array)-1
$numero= $len-1
$num=StringInStr($path,$delimiter,0,$numero)
$dir=StringMid($path,1,$num)
return $dir
EndFunc
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...