adrianodj Posted May 29, 2011 Share Posted May 29, 2011 hi all I have a listwiev and 3 buttons: add file, run and deleteI 1 - I want the listview shows me the contents of a particular folder without having to give the add file button 2 - with the delete button I want to delete the file I have selectioned thanks expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> #include <GuiListView.au3> #include <Constants.au3> #include <Misc.au3> #include <GuiToolTip.au3> #include <Array.au3> Global $ITEMID, $Lista1 Global $CABECERA = "Archivo |Ruta " $Ancho = 333 $Alto = 300 #Region ### START Koda GUI section ### $Form1 = GUICreate("Aplicacion", $Ancho, $Alto, 318, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) ;;;; LISTA $Lista1 = GUICtrlCreateListView($CABECERA, 0, 0, $Ancho, 257) GUICtrlSetState($Lista1, $GUI_DROPACCEPTED) _GUICtrlListView_SetExtendedListViewStyle($Lista1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP)) ;;;; BOTONES $BTNAGREGAR = GUICtrlCreateButton("Add file", 15, 265, 90, 25) GUICtrlSetTip(-1, 'Añadir archivos ') $BTNEMPEZAR = GUICtrlCreateButton("Run", 123, 265, 90, 25) GUICtrlSetTip(-1, 'Ejecutar') $BTNBORARSELECT = GUICtrlCreateButton("Delete", 230, 265, 90, 25) GUICtrlSetTip(-1, 'Borrar') GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $BTNAGREGAR _Agregararchivo() Case $BTNEMPEZAR _SelectArchivo() Case $BTNBORARSELECT _BorrarSeleccionado() EndSwitch WEnd Func _Agregararchivo() $Carpeta = FileOpenDialog('Add file, '', 'All (*)', 5, '', $Form1) ;<-------------???????????????? I want the listview shows me the contents of a particular folder without having to give the add file button C:\Pruebas\ .... .exe $Filediv = StringSplit($Carpeta, '|') If $Filediv[0] <> 1 Then ; For $N = 2 To $Filediv[0] $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($Filediv[$N], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $Filediv[1] & '\' & $Filediv[$N], 1) Next Else $Filediv = StringSplit($Carpeta, '\') ;Añadir un archivo $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($Filediv[$Filediv[0]], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $Carpeta, 1) EndIf EndFunc ;==>_Agregararchivo Func _SelectArchivo() If _GUICtrlListView_GetItemCount($Lista1) <> 0 Then $A = 0 Do $A = $A + 1 If _GUICtrlListView_GetItemSelected($Lista1, $A) = True Then $Archivo = $A _Aplicar(_GUICtrlListView_GetItemText($Lista1, $A, 1)) $A = _GUICtrlListView_GetItemCount($Lista1) $Selection = 0 Else $Selection = 1 EndIf Until $A = _GUICtrlListView_GetItemCount($Lista1) If $Selection = 1 Then $Archivo = 0 _Aplicar(_GUICtrlListView_GetItemText($Lista1, 0, 1)) _GUICtrlListView_SetItemSelected($Lista1, 0) EndIf EndIf EndFunc ;==>_SelectArchivo Func _Aplicar($RUTAF) $Aplicar = ShellExecute($RUTAF) EndFunc ;==>_Aplicar Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = 1 then $ELIMINADO = _GUICtrlListView_GetSelectedCount($Lista1) _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($Lista1)) FileDelete($ELIMINADO) ; <--------------------???????????????????????????????????????????????????????? with the delete button I want to delete the file I have selectioned $ITEMID = $ITEMID - $ELIMINADO Else EndIf EndFunc ;==>_BorrarSeleccionado Link to comment Share on other sites More sharing options...
ahmet Posted May 29, 2011 Share Posted May 29, 2011 Here is modified version of your function _BorrarSeleccionado Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = "1" then MsgBox(0,"","test") $selected=_GUICtrlListView_GetSelectedIndices (GUICtrlGetHandle($Lista1),True) ConsoleWrite("index=" & $selected[1] & @CRLF) $path=_GUICtrlListView_GetItemText (GUICtrlGetHandle($Lista1),$selected[1],1) ConsoleWrite($path & @CRLF) _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($Lista1)) FileDelete($path) ; <--------------------???????????????????????????????????????????????????????? with the delete button I want to delete the file I have selectioned ;~ $ITEMID = $ITEMID - $ELIMINADO Else EndIf EndFunc ;==>_BorrarSeleccionado Can you explain better your first question? Link to comment Share on other sites More sharing options...
adrianodj Posted May 29, 2011 Author Share Posted May 29, 2011 Here is modified version of your function _BorrarSeleccionado Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = "1" then MsgBox(0,"","test") $selected=_GUICtrlListView_GetSelectedIndices (GUICtrlGetHandle($Lista1),True) ConsoleWrite("index=" & $selected[1] & @CRLF) $path=_GUICtrlListView_GetItemText (GUICtrlGetHandle($Lista1),$selected[1],1) ConsoleWrite($path & @CRLF) _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($Lista1)) FileDelete($path) ; <--------------------???????????????????????????????????????????????????????? with the delete button I want to delete the file I have selectioned ;~ $ITEMID = $ITEMID - $ELIMINADO Else EndIf EndFunc ;==>_BorrarSeleccionado Can you explain better your first question? hello BorrarSeleccionado;==>_ function is deleting only the name of the listview on the hdd the file is not deleted at the first point I want when I run the script in the listview show the contents of a folder hdd C:\prueba\ many archivos.exe without pressing AddButton and choose files sorry for bad English thanks Link to comment Share on other sites More sharing options...
ahmet Posted May 29, 2011 Share Posted May 29, 2011 For me it deletes files. What OS are you using? For adding items at startup look at _FileListToArray() and create loop for creating listviewitems based on return from _FileListToArray()function. Link to comment Share on other sites More sharing options...
adrianodj Posted May 29, 2011 Author Share Posted May 29, 2011 For me it deletes files. What OS are you using?For adding items at startup look at _FileListToArray() and create loop for creating listviewitems based on return from _FileListToArray()function.I have windows 7the comand filedelet not work for me is my problem sorryCan you explain me how I can make the loop I've tried and I could not do anything I am very beginner thanks Link to comment Share on other sites More sharing options...
ahmet Posted May 29, 2011 Share Posted May 29, 2011 This is the loop$files=_FileListToArray($default_path,"*",1) For $i=1 To $files[0] GUICtrlCreateListViewItem($files[$i] & "|" & $default_path & $files[$i],$Lista1) Next Put it after setting listviw's extended style. What does this line outputs? ConsoleWrite($path & @CRLF) Link to comment Share on other sites More sharing options...
adrianodj Posted May 31, 2011 Author Share Posted May 31, 2011 This is the loop$files=_FileListToArray($default_path,"*",1) For $i=1 To $files[0] GUICtrlCreateListViewItem($files[$i] & "|" & $default_path & $files[$i],$Lista1) Next Put it after setting listviw's extended style. What does this line outputs? ConsoleWrite($path & @CRLF) everything works fine thank you very much Link to comment Share on other sites More sharing options...
AndyCollette Posted November 13, 2011 Share Posted November 13, 2011 everything works fine thank you very muchcould you please post your finished script. I am a noob trying to use these same features,thx! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 13, 2011 Moderators Share Posted November 13, 2011 AndyCollette,Here is my take on how you might do it. The ####### lines show the areas I changed from the OP's first script: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> #include <GuiListView.au3> #include <Constants.au3> #include <Misc.au3> #include <GuiToolTip.au3> #include <Array.au3> #include <File.au3> Global $ITEMID, $Lista1 Global $CABECERA = "Archivo |Ruta " $Ancho = 333 $Alto = 300 #region ### START Koda GUI section ### $Form1 = GUICreate("Aplicacion", $Ancho, $Alto, 318, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) ;;;; LISTA $Lista1 = GUICtrlCreateListView($CABECERA, 0, 0, $Ancho, 257) GUICtrlSetState($Lista1, $GUI_DROPACCEPTED) _GUICtrlListView_SetExtendedListViewStyle($Lista1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP)) ;;;; BOTONES $BTNAGREGAR = GUICtrlCreateButton("Add file", 15, 265, 90, 25) GUICtrlSetTip(-1, 'Añadir archivos ') $BTNEMPEZAR = GUICtrlCreateButton("Run", 123, 265, 90, 25) GUICtrlSetTip(-1, 'Ejecutar') $BTNBORARSELECT = GUICtrlCreateButton("Delete", 230, 265, 90, 25) GUICtrlSetTip(-1, 'Borrar') GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### ; ############################################################################### Global $sFolder = FileSelectFolder("Select a folder", "") $aList = _FileListToArray($sFolder, "*.*", 1) For $i = 1 To $aList[0] $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($aList[$i], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $sFolder & '\' & $aList[$i], 1) Next ; ############################################################################### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $BTNAGREGAR _Agregararchivo() Case $BTNEMPEZAR _SelectArchivo() Case $BTNBORARSELECT _BorrarSeleccionado() EndSwitch WEnd Func _Agregararchivo() $Carpeta = FileOpenDialog('Add file', '', ' All(*.*) ', 5, '', $Form1) $Filediv = StringSplit($Carpeta, '|') If $Filediv[0] <> 1 Then ; For $N = 2 To $Filediv[0] $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($Filediv[$N], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $Filediv[1] & '\' & $Filediv[$N], 1) Next Else $Filediv = StringSplit($Carpeta, '\') ;Añadir un archivo $ITEMID = _GUICtrlListView_AddItem($Lista1, StringTrimRight($Filediv[$Filediv[0]], 4)) _GUICtrlListView_AddSubItem($Lista1, $ITEMID, $Carpeta, 1) EndIf EndFunc ;==>_Agregararchivo Func _SelectArchivo() If _GUICtrlListView_GetItemCount($Lista1) <> 0 Then $A = 0 Do $A = $A + 1 If _GUICtrlListView_GetItemSelected($Lista1, $A) = True Then $Archivo = $A _Aplicar(_GUICtrlListView_GetItemText($Lista1, $A, 1)) $A = _GUICtrlListView_GetItemCount($Lista1) $Selection = 0 Else $Selection = 1 EndIf Until $A = _GUICtrlListView_GetItemCount($Lista1) If $Selection = 1 Then $Archivo = 0 _Aplicar(_GUICtrlListView_GetItemText($Lista1, 0, 1)) _GUICtrlListView_SetItemSelected($Lista1, 0) EndIf EndIf EndFunc ;==>_SelectArchivo Func _Aplicar($RUTAF) $Aplicar = ShellExecute($RUTAF) EndFunc ;==>_Aplicar ; ############################################################################### Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = 1 Then $ELIMINADO = _GUICtrlListView_GetSelectedIndices($Lista1, True) ; Get an array of teh selected indices For $i = 1 To $ELIMINADO[0] $sText = _GUICtrlListView_GetItemText($Lista1, $ELIMINADO[$i], 1) FileDelete($sText) _GUICtrlListView_DeleteItem(GUICtrlGetHandle($Lista1), $ELIMINADO[$i]) Next Else EndIf EndFunc ;==>_BorrarSeleccionado ; ###############################################################################Please ask if you have any questions. M23 l3ill 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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