telmob Posted January 5, 2013 Share Posted January 5, 2013 I've recently found this post:and changed a bit for my needs.I basically want the files to show the path in the first column and the file extension in the second column.This works alright for single files, but for multiple files, i can't do it, because of stringtrim in the array.Is there a way to do this?Please don't pay attention to stringtrim sillyness. I know its noobish but its working. Spent about an hour reading stringregexp to do the same and couldn't. 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, $ListWhitelist Global $CABECERA = "Objects allowed to run |Type " $Ancho = 393 $Alto = 300 #region ### START Koda GUI section ### $SRPEGUI = GUICreate("Aplicacion", $Ancho, $Alto, 398, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) ;;;; LISTA $ListWhitelist = GUICtrlCreateListView($CABECERA, 0, 0, $Ancho, 257) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 333) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 56) GUICtrlSetState($ListWhitelist, $GUI_DROPACCEPTED) _GUICtrlListView_SetExtendedListViewStyle($ListWhitelist, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP)) ;;;; BUTTONS $ButtonAddFileWhitelist = GUICtrlCreateButton("Add file", 15, 265, 90, 25) $ButtonAddFolderWhitelist = GUICtrlCreateButton("Add Folder", 123, 265, 90, 25) $BTNBORARSELECT = GUICtrlCreateButton("Delete", 230, 265, 90, 25) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $ButtonAddFileWhitelist _AddFileAllow() Case $ButtonAddFolderWhitelist _AddFolderAllow() Case $BTNBORARSELECT _BorrarSeleccionado() EndSwitch WEnd Func _AddFileAllow() $Carpeta = FileOpenDialog("Select executable to add to the Whitelist.", @WindowsDir & "", "Known Executables (*.A6P;*.AC;*.AS;*.ACR;*.ACTION;*.AIR;*.APP;*.AWK;*.CGI;*.CSH;*.DEK;*.DLD;*.DS;*.EBM;*.ESH;*.EZS;*.FKY;*.FRS;*.FXP;*.GADGET;*.HMS;*.ICD;*.INX;*.IPF;*.ISU;*.JAR;*.JS;*.JSE;*.JSX;*.KIX;*.LUA;*.MCR;*.MEM;*.MPX;*.MS;*.OBS;*.PAF;*.PEX;*.PRC;*.PRG;*.PVD;*.PWC;*.PY;*.PYC;*.PYO;*.QPX;*.RBX;*.RGS;*.ROX;*.RPJ;*.SCAR;*.SCRIPT;*.SCT;*.SHB;*.SPR;*.TLB;*.TMS;*.U3P;*.UDF;*.VBE;*.VBS;*.VBSCRIPT;*.WCM;*.WPK;*.WS;*.WSF;*.XQT;*.AUT;*.AU3;*.A3X;*.ADE;*.ADP;*.BAS;*.BAT;*.CHM;*.CMD;*.COM;*.CPL;*.CRT;*.EXE;*.HLP;*.HTA;*.INF;*.INS;*.ISP;*.MDB;*.MDE;*.MSC;*.MSI;*.MSP;*.MST;*.OCX;*.PCD;*.PIF;*.REG;*.SCR;*.SHS;*.URL;*.VB;*.WSC)", 5, '', $SRPEGUI) $Filediv = StringSplit($Carpeta, '|') If $Filediv[0] <> 1 Then ; For $N = 2 To $Filediv[0][0] $result = StringRight($Filediv[$Filediv[0]], 4) $result2 = StringLeft($result, 1) $result3 = StringRight($Filediv[$Filediv[0]], 3) $result4 = StringLeft($result3, 1) $result5 = StringRight($Filediv[$Filediv[0]], 2) $result6 = StringLeft($result5, 1) If $result2 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 4) If $result4 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 3) If $result6 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 2) $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, StringTrimRight($Filediv[$N], 4)) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $Filediv[1] & '\' & $Filediv[$N], 1) Next Else $Filediv = StringSplit($Carpeta, '\') ;AƱadir un archivo $result = StringRight($Filediv[$Filediv[0]], 4) $result2 = StringLeft($result, 1) $result3 = StringRight($Filediv[$Filediv[0]], 3) $result4 = StringLeft($result3, 1) $result5 = StringRight($Filediv[$Filediv[0]], 2) $result6 = StringLeft($result5, 1) If $result2 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 4) If $result4 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 3) If $result6 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 2) If $Carpeta <> "" Then $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $Carpeta, 2) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $Filediv, 1) EndIf EndIf EndFunc ;==>_AddFileAllow Func _AddFolderAllow() $sFolder = FileSelectFolder("Select a folder", "") $result = StringTrimLeft($sFolder, 1) $result2 = StringLeft($result, 2) If $result2 <>":\" And $sFolder <>"" Then MsgBox(48, "Path not allowed", "Only absolute folder paths are accepted." & @CRLF & @CRLF & "Select another folder.") _AddFolderAllow() EndIf If $sFolder <>"" And $result2 =":\" Then $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sFolder, 4) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, 'Folder', 1) EndIf EndFunc ; ############################################################################### Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = 1 Then $ELIMINADO = _GUICtrlListView_GetSelectedIndices($ListWhitelist, True) ; Get an array of the selected indices For $i = 1 To $ELIMINADO[0] $sText = _GUICtrlListView_GetItemText($ListWhitelist, $ELIMINADO[$i], 0) ;~ FileDelete($sText) MsgBox("1", "Atencion", $sText) _GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListWhitelist), $ELIMINADO[$i]) Next Else EndIf EndFunc ;==>_BorrarSeleccionado ; ############################################################################### Link to comment Share on other sites More sharing options...
BrewManNH Posted January 5, 2013 Share Posted January 5, 2013 Just took a quick run through with this, here's a couple of points you need to fix. For $N = 2 To $Filediv[0][0] StringSplit returns a 1D array, not a 2D array. If $result2 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 4) You've just deleted the contents of the array $FileDiv and turned it into a simple variable so that the script will error out when you try to access it as an array again. You aren't using the element of $filediv to put the string into, you're turning it into a string variable. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. Ā - Ā ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. Ā - Ā Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. Ā - Ā _FileGetProperty - Retrieve the properties of a file Ā - Ā SciTE Toolbar - A toolbar demo for use with the SciTE editor Ā - Ā GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. Ā - Ā Ā Latin Square password generator Link to comment Share on other sites More sharing options...
telmob Posted January 5, 2013 Author Share Posted January 5, 2013 Thanks for your reply BrewManNH. Just took a quick run through with this, here's a couple of points you need to fix. For $N = 2 To $Filediv[0][0] StringSplit returns a 1D array, not a 2D array. Yep, that's my big problem. And i have no idea how to solve it If $result2 ="." Then $Filediv=Stringright($Filediv[$Filediv[0]], 4) You've just deleted the contents of the array $FileDiv and turned it into a simple variable so that the script will error out when you try to access it as an array again. You aren't using the element of $filediv to put the string into, you're turning it into a string variable. I'm searching the forums for a possible solution, but so far... i'm completely lost. I've spent the last two days trying to solve this and i was without internet at home, so my brain is completely fried. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 5, 2013 Share Posted January 5, 2013 (edited) Thanks for your reply BrewManNH. Yep, that's my big problem. And i have no idea how to solve it Use $filediv[0] instead. You should probably look at some of the array tutorials. I'm searching the forums for a possible solution, but so far... i'm completely lost. I've spent the last two days trying to solve this and i was without internet at home, so my brain is completely fried. You spent 2 days trying to figure out how to change the variable name, or 2 days trying to figure out how to assign a value to an array element? Either way, you spent 47 hours and 55 minutes too long doing it. You should do something like this. 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, $ListWhitelist Global $CABECERA = "Objects allowed to run |Type " $Ancho = 393 $Alto = 300 #region ### START Koda GUI section ### $SRPEGUI = GUICreate("Aplicacion", $Ancho, $Alto, 398, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) ;;;; LISTA $ListWhitelist = GUICtrlCreateListView($CABECERA, 0, 0, $Ancho, 257) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 333) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 56) GUICtrlSetState($ListWhitelist, $GUI_DROPACCEPTED) _GUICtrlListView_SetExtendedListViewStyle($ListWhitelist, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP)) ;;;; BUTTONS $ButtonAddFileWhitelist = GUICtrlCreateButton("Add file", 15, 265, 90, 25) $ButtonAddFolderWhitelist = GUICtrlCreateButton("Add Folder", 123, 265, 90, 25) $BTNBORARSELECT = GUICtrlCreateButton("Delete", 230, 265, 90, 25) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $ButtonAddFileWhitelist _AddFileAllow() Case $ButtonAddFolderWhitelist _AddFolderAllow() Case $BTNBORARSELECT _BorrarSeleccionado() EndSwitch WEnd ; ############################################################################### Func _AddFileAllow() Local $sDrive, $sPath, $sName, $sExt $Carpeta = FileOpenDialog("Select executable to add to the Whitelist.", @WindowsDir & "", "Known Executables (*.A6P;*.AC;*.AS;*.ACR;*.ACTION;*.AIR;*.APP;*.AWK;*.CGI;*.CSH;*.DEK;*.DLD;*.DS;*.EBM;*.ESH;*.EZS;*.FKY;*.FRS;*.FXP;*.GADGET;*.HMS;*.ICD;*.INX;*.IPF;*.ISU;*.JAR;*.JS;*.JSE;*.JSX;*.KIX;*.LUA;*.MCR;*.MEM;*.MPX;*.MS;*.OBS;*.PAF;*.PEX;*.PRC;*.PRG;*.PVD;*.PWC;*.PY;*.PYC;*.PYO;*.QPX;*.RBX;*.RGS;*.ROX;*.RPJ;*.SCAR;*.SCRIPT;*.SCT;*.SHB;*.SPR;*.TLB;*.TMS;*.U3P;*.UDF;*.VBE;*.VBS;*.VBSCRIPT;*.WCM;*.WPK;*.WS;*.WSF;*.XQT;*.AUT;*.AU3;*.A3X;*.ADE;*.ADP;*.BAS;*.BAT;*.CHM;*.CMD;*.COM;*.CPL;*.CRT;*.EXE;*.HLP;*.HTA;*.INF;*.INS;*.ISP;*.MDB;*.MDE;*.MSC;*.MSI;*.MSP;*.MST;*.OCX;*.PCD;*.PIF;*.REG;*.SCR;*.SHS;*.URL;*.VB;*.WSC)", 5, '', $SRPEGUI) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Carpeta = ' & $Carpeta & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Filediv = StringSplit($Carpeta, '|') If $Filediv[0] <> 1 Then ; For $N = 2 To $Filediv[0] $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $Filediv[1]) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $Filediv[$N], 1) Next Else _PathSplit($Carpeta, $sDrive, $sPath, $sName, $sExt) If $Carpeta <> "" Then $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sDrive & $sPath) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $sName & $sExt, 1) EndIf EndIf EndFunc ;==>_AddFileAllow Func _AddFolderAllow() $sFolder = FileSelectFolder("Select a folder", "") $result = StringTrimLeft($sFolder, 1) $result2 = StringLeft($result, 2) If $result2 <> ":\" And $sFolder <> "" Then MsgBox(48, "Path not allowed", "Only absolute folder paths are accepted." & @CRLF & @CRLF & "Select another folder.") _AddFolderAllow() EndIf If $sFolder <> "" And $result2 = ":\" Then $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sFolder, 4) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, 'Folder', 1) EndIf EndFunc ;==>_AddFolderAllow ; ############################################################################### Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = 1 Then $ELIMINADO = _GUICtrlListView_GetSelectedIndices($ListWhitelist, True) ; Get an array of the selected indices For $i = 1 To $ELIMINADO[0] $sText = _GUICtrlListView_GetItemText($ListWhitelist, $ELIMINADO[$i], 0) ;~ FileDelete($sText5) MsgBox("1", "Atencion", $sText) _GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListWhitelist), $ELIMINADO[$i]) Next Else EndIf EndFunc ;==>_BorrarSeleccionado Please note, I only fixed the AddFileAllow function, I'll leave the folder one to you. EDIT: Modified the section that is used when more than one file is selected, didn't make sense to add the path then split it to get it back again. Old code I didn't change before posting. Edited January 5, 2013 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. Ā - Ā ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. Ā - Ā Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. Ā - Ā _FileGetProperty - Retrieve the properties of a file Ā - Ā SciTE Toolbar - A toolbar demo for use with the SciTE editor Ā - Ā GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. Ā - Ā Ā Latin Square password generator Link to comment Share on other sites More sharing options...
telmob Posted January 5, 2013 Author Share Posted January 5, 2013 I really apreciate it. But i think you didn't understand what i wanted, or maybe i didn't explain properly. The folder is bahaving as it should. _PathSplit is genious! I didn't even knew it existed I really have to study a bit of arrays and stringregexp, i get into so many problems because of these... And what i was looking for was exactly this: expandcollapse popup#include #include #include #include #include #include #include #include #include #include #include #include Global $ITEMID, $ListWhitelist Global $CABECERA = "Objects allowed to run |Type " $Ancho = 393 $Alto = 300 #region ### START Koda GUI section ### $SRPEGUI = GUICreate("Aplicacion", $Ancho, $Alto, 398, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) ;;;; LISTA $ListWhitelist = GUICtrlCreateListView($CABECERA, 0, 0, $Ancho, 257) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 333) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 56) GUICtrlSetState($ListWhitelist, $GUI_DROPACCEPTED) _GUICtrlListView_SetExtendedListViewStyle($ListWhitelist, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP)) ;;;; BUTTONS $ButtonAddFileWhitelist = GUICtrlCreateButton("Add file", 15, 265, 90, 25) $ButtonAddFolderWhitelist = GUICtrlCreateButton("Add Folder", 123, 265, 90, 25) $BTNBORARSELECT = GUICtrlCreateButton("Delete", 230, 265, 90, 25) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $ButtonAddFileWhitelist _AddFileAllow() Case $ButtonAddFolderWhitelist _AddFolderAllow() Case $BTNBORARSELECT _BorrarSeleccionado() EndSwitch WEnd ; ############################################################################### Func _AddFileAllow() Local $sDrive, $sPath, $sName, $sExt $Carpeta = FileOpenDialog("Select executable to add to the Whitelist.", @WindowsDir & "", "Known Executables (*.A6P;*.AC;*.AS;*.ACR;*.ACTION;*.AIR;*.APP;*.AWK;*.CGI;*.CSH;*.DEK;*.DLD;*.DS;*.EBM;*.ESH;*.EZS;*.FKY;*.FRS;*.FXP;*.GADGET;*.HMS;*.ICD;*.INX;*.IPF;*.ISU;*.JAR;*.JS;*.JSE;*.JSX;*.KIX;*.LUA;*.MCR;*.MEM;*.MPX;*.MS;*.OBS;*.PAF;*.PEX;*.PRC;*.PRG;*.PVD;*.PWC;*.PY;*.PYC;*.PYO;*.QPX;*.RBX;*.RGS;*.ROX;*.RPJ;*.SCAR;*.SCRIPT;*.SCT;*.SHB;*.SPR;*.TLB;*.TMS;*.U3P;*.UDF;*.VBE;*.VBS;*.VBSCRIPT;*.WCM;*.WPK;*.WS;*.WSF;*.XQT;*.AUT;*.AU3;*.A3X;*.ADE;*.ADP;*.BAS;*.BAT;*.CHM;*.CMD;*.COM;*.CPL;*.CRT;*.EXE;*.HLP;*.HTA;*.INF;*.INS;*.ISP;*.MDB;*.MDE;*.MSC;*.MSI;*.MSP;*.MST;*.OCX;*.PCD;*.PIF;*.REG;*.SCR;*.SHS;*.URL;*.VB;*.WSC)", 5, '', $SRPEGUI) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Carpeta = ' & $Carpeta & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Filediv = StringSplit($Carpeta, '|') If $Filediv[0] <> 1 Then ; For $N = 2 To $Filediv[0] _PathSplit($Filediv[1] & "\" & $Filediv[$N], $sDrive, $sPath, $sName, $sExt) $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sDrive & $sPath & $sName & $sExt) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $sExt, 1) Next Else _PathSplit($Carpeta, $sDrive, $sPath, $sName, $sExt) If $Carpeta <> "" Then $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sDrive & $sPath & $sName & $sExt) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $sExt, 1) EndIf EndIf EndFunc ;==>_AddFileAllow Func _AddFolderAllow() $sFolder = FileSelectFolder("Select a folder", "") $result = StringTrimLeft($sFolder, 1) $result2 = StringLeft($result, 2) If $result2 <> ":\" And $sFolder <> "" Then MsgBox(48, "Path not allowed", "Only absolute folder paths are accepted." & @CRLF & @CRLF & "Select another folder.") _AddFolderAllow() EndIf If $sFolder <> "" And $result2 = ":\" Then $ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sFolder, 4) _GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, 'Folder', 1) EndIf EndFunc ;==>_AddFolderAllow ; ############################################################################### Func _BorrarSeleccionado() $var = MsgBox("1", "Atencion", "Estas seguro que quieres Borarlo?") If $var = 1 Then $ELIMINADO = _GUICtrlListView_GetSelectedIndices($ListWhitelist, True) ; Get an array of the selected indices For $i = 1 To $ELIMINADO[0] $sText = _GUICtrlListView_GetItemText($ListWhitelist, $ELIMINADO[$i], 0) ;~ FileDelete($sText5) MsgBox("1", "Atencion", $sText) _GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListWhitelist), $ELIMINADO[$i]) Next Else EndIf EndFunc ;==>_BorrarSeleccionado Again... Thank you! 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