Sign in to follow this  
Followers 0
aness07

how to delet file from listview

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thank you

Danyfirex

But this will help me to remove only the first file ... I want to remove a file the user choose it

Thank you again

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you Danyfirex very much ... It works well

:ILA::ILA2::ILA3:

You're welcome. regards

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0