Leaderboard
Popular Content
Showing content with the highest reputation on 05/30/2017 in all areas
-
Get the file name and the file directory from a file path
ahmeddzcom reacted to Rofellos for a topic
These functions are very useful if you got a file path and want the name or the directory of the file. ; #FUNCTION# ====================================================================================================== ; Name...........: GetDir ; Description ...: Returns the directory of the given file path ; Syntax.........: GetDir($sFilePath) ; Parameters ....: $sFilePath - File path ; Return values .: Success - The file directory ; Failure - -1, sets @error to: ; |1 - $sFilePath is not a string ; Author ........: Renan Maronni <renanmaronni@hotmail.com> ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ================================================================================================================== Func GetDir($sFilePath) Local $aFolders = StringSplit($sFilePath, "\") Local $iArrayFoldersSize = UBound($aFolders) Local $FileDir = "" If (Not IsString($sFilePath)) Then Return SetError(1, 0, -1) EndIf $aFolders = StringSplit($sFilePath, "\") $iArrayFoldersSize = UBound($aFolders) For $i = 1 To ($iArrayFoldersSize - 2) $FileDir &= $aFolders[$i] & "\" Next Return $FileDir EndFunc ;==>GetDir ; #FUNCTION# ====================================================================================================== ; Name...........: GetFileName ; Description ...: Returns the file name of the given file path ; Syntax.........: GetFileName($sFilePath) ; Parameters ....: $sFilePath - File path ; Return values .: Success - The file name ; Failure - -1, sets @error to: ; |1 - $sFilePath is not a string ; Author ........: Renan Maronni <renanmaronni@hotmail.com> ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =================================================================================================================== Func GetFileName($sFilePath) Local $aFolders = "" Local $FileName = "" Local $iArrayFoldersSize = 0 If (Not IsString($sFilePath)) Then Return SetError(1, 0, -1) EndIf $aFolders = StringSplit($sFilePath, "\") $iArrayFoldersSize = UBound($aFolders) $FileName = $aFolders[($iArrayFoldersSize - 1)] Return $FileName EndFunc ;==>GetFileName1 point -
[Solved] Concatenating two column-based arrays
anthonyjr2 reacted to benners for a topic
You could Redim the largest array to account for the extra columns in the smallest array and use _ArrayColInsert in a loop to add them together or something like below. Will only work work with 1D array, I think #include <Array.au3> local $array1[1][10] = [[0]] local $array2[1][30] = [[1]] _ArrayTranspose($array1) _ArrayTranspose($array2) _ArrayConcatenate($array1, $array2) _ArrayTranspose($array1) _ArrayDisplay($array1)1 point -
Agreed but if ever the IDs are not sequential or the OP want reordering things, an array index becomes unsuitable. I don't have enough information about the actual OP application to decide otherwise. Looking up a key in a map isn't going to take many cycles.1 point
-
[SOLVED] Most efficient way to associate Control IDs with an array of data?
cosmos reacted to InunoTaishou for a topic
I don't think you really need to use a map for this. Since the control ID is an int anyway, you can just use that as the index to an array holding data. (I.e., $aArrayOfData[GUICtrlCreateTreeViewItem($thisName, $treeview)]) #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Example() Func Example() Local $aData[0] GUICreate("My GUI with treeview", 350, 215) Local $idTreeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Local $idGeneralitem = AddTreevViewItem($aData, $idTreeview, "General", "TreeView Demo") GUICtrlSetColor(-1, 0x0000C0) Local $idDisplayitem = AddTreevViewItem($aData, $idTreeview, "Display", "") GUICtrlSetColor(-1, 0x0000C0) Local $idAboutitem = AddTreevViewItem($aData, $idGeneralitem, "About", "This little scripts demonstates the using of a treeview-control.") Local $idCompitem = AddTreevViewItem($aData, $idGeneralitem, "Computer", "Name:" & @TAB & @ComputerName & @CRLF & "OS:" & @TAB & @OSVersion & @CRLF & "SP:" & @TAB & @OSServicePack) AddTreevViewItem($aData, $idGeneralitem, "User", @UserName) AddTreevViewItem($aData, $idDisplayitem, "Resolution", @DesktopWidth & "x" & @DesktopHeight) Local $idLast = AddTreevViewItem($aData, $idDisplayitem, "Other", "") Local $lblMessage = GUICtrlCreateLabel("TreeView Demo", 110, 6, 220, 150) GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN) Local $idTogglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20) Local $idInfobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20) Local $idStatebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20) Local $idCancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20) GUICtrlSetState($idGeneralitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold GUICtrlSetState($idDisplayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold GUISetState(@SW_SHOW) Local $idMsg, $idItem, $hItem, $sText ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $idCancelbutton Or $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idTogglebutton ; Toggle the bold painting If BitAND(GUICtrlRead($idGeneralitem), $GUI_DEFBUTTON) Then GUICtrlSetState($idGeneralitem, 0) GUICtrlSetState($idDisplayitem, 0) Else GUICtrlSetState($idGeneralitem, $GUI_DEFBUTTON) GUICtrlSetState($idDisplayitem, $GUI_DEFBUTTON) EndIf Case $idMsg = $idInfobutton $idItem = GUICtrlRead($idTreeview) ; Get the controlID of the current selected treeview item If $idItem = 0 Then MsgBox($MB_SYSTEMMODAL, "TreeView Demo", "No item currently selected") Else $sText = GUICtrlRead($idItem, 1) ; Get the text of the treeview item If $sText == "" Then MsgBox($MB_SYSTEMMODAL, "Error", "Error while retrieving infos about item") Else MsgBox($MB_SYSTEMMODAL, "TreeView Demo", "Current item selected is: " & $sText) EndIf EndIf Case $idMsg = $idStatebutton $idItem = GUICtrlRead($idTreeview) If $idItem > 0 Then $hItem = GUICtrlGetHandle($idItem) GUICtrlSendMsg($idTreeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem) EndIf ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter) Case $idMsg >= $idGeneralitem and $idMsg <= $idLast GUICtrlSetData($lblMessage, $aData[$idMsg]) EndSelect WEnd GUIDelete() EndFunc ;==>Example Func AddTreevViewItem(ByRef $aItems, $idTreeView, $sText, $sMessage) Local $iId = GUICtrlCreateTreeViewItem($sText, $idTreeview) ReDim $aItems[$iId + 1] $aItems[$iId] = $sMessage Return $iId EndFunc1 point -
Hello ! Here is a small function which allows you to make changes in the Firefox configuration file (of the user running the script) Warning : to make changes into the configuration file, Firefox must be stopped Here you can find some settings in this webpage : http://kb.mozillazine.org/About:config_entries Examples : ; Changes the start page _FF_Config("browser.startup.homepage", "http://www.autoitscript.com/forum") ; Set a manual proxy _FF_Config("network.proxy.type", 1) ; Sets the proxy in manual mode _FF_Config("network.proxy.http", "192.168.1.10") ; Sets the http proxy name/IP _FF_Config("network.proxy.http_port", 3128) ; Sets the http proxy port _FF_Config("network. proxy. autoconfig_url") ; Remove the proxy url ; Allow popups _FF_Config("dom.disable_open_during_load", false) Also, you can use _FF_GetProfileList() to retrieve the list of Firefox profiles for the current user. Now, the two functions : #include <File.au3> ; needed for _PathFull ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FF_Config ; Description ...: Configures Mozilla Firefox ; Syntax ........: _FF_Config($sSettingName[, $sSettingValue = Null[, $sProfileName = ""]]) ; Parameters ....: $sSettingName - Name of the setting to add, change or delete. ; $sSettingValue - [optional] Value of the setting. Default is Null = deletes the line. ; $sProfileName - [optional] Name of the Firefox profile. Default is "" = all Firefox profiles ; Return values .: Success - Returns 1 ; Failure - Returns 0 and set @error to : ; 1 : Unable to list the Firefox profiles ; 2 : Unable to load the specified Firefox profile ; 3 : Firefox is running ; Author ........: jguinch ; =============================================================================================================================== Func _FF_Config($sSettingName, $sSettingValue = Null, $sProfileName = "") Local $sFFConfigFile = "prefs.js" Local $sContent, $aProfiles = _FF_GetProfileList(), $iError = 0, $hPrefs If @error Then Return SetError(@error, 0, 0) If ProcessExists("firefox.exe") Then Return SetError(3, 0, 0) If IsString($sSettingValue) Then $sSettingValue = '"' & $sSettingValue & '"' If IsBool($sSettingValue) Then $sSettingValue = StringLower($sSettingValue) For $i = 1 To $aProfiles[0][0] If $sProfileName <> "" AND $aProfiles[$i][0] <> $sProfileName Then ContinueLoop $sContent = FileRead($aProfiles[$i][1] & "\" & $sFFConfigFile) If @error Then Return SetError(2, 0, 0) If $sSettingValue = Null Then $sNewContent = StringRegExpReplace($sContent, '(?mi)^\Quser_pref("' & $sSettingName & '"\E\V+\R', '') Else $sNewContent = StringRegExpReplace($sContent, '(?mi)^\Quser_pref("' & $sSettingName & '", \E\K.+(?=\);$)', $sSettingValue) If NOT @extended Then $sNewContent = StringRegExpReplace($sContent, ";\K\v*$", @CRLF & 'user_pref("' & $sSettingName & '", ' & $sSettingValue & ');' & @CRLF) EndIf $hPrefs = FileOpen($aProfiles[$i][1] & "\" & $sFFConfigFile, 2) If $hPrefs = -1 Then Return SetError(2, 0, 0) FileWrite($hPrefs, $sNewContent) FileClose($hPrefs) Next Return 1 EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FF_GetProfileList ; Description ...: List the Firefox profiles in a 2D array ; Syntax ........: _FF_GetProfileList() ; Parameters ....: None ; Return values .: Success - Returns a 2D array (see remarks) ; Failure - Returns 0 and set @error to 1 (unable to list the Firefox profiles) ; Author ........: jguinch ; Remarks........: The array returned is two-dimensional and is made up as follows: ; $aArray[0][0] : Number of profiles ; $aArray[0][1] : Default profile index in the array ; $aArray[1][0] : 1st profile name ; $aArray[1][1] : 1st profile path ; ... ; $aArray[n][0] : nth profile name ; $aArray[n][1] : nth profile path ; =============================================================================================================================== Func _FF_GetProfileList() Local $sProfileName, $sIsRelative, $sProfilePath, $aResult[10][2] = [[0]] Local $sFFAppDataPah = @AppDataDir & "\Mozilla\Firefox" Local $sProfiles = $sFFAppDataPah & "\profiles.ini" Local $aSections = IniReadSectionNames($sProfiles) If @error OR NOT IsArray($aSections) Then Return SetError(1, 1, 0) For $i = 1 To $aSections[0] If $aSections[$i] <> "General" Then $sProfileName = IniRead($sProfiles, $aSections[$i], "Name", "") $sIsRelative = IniRead($sProfiles, $aSections[$i], "IsRelative", "") $sProfilePath = IniRead($sProfiles, $aSections[$i], "Path", "") If $sIsRelative = "" OR $sProfilePath = "" OR $sProfileName = "" Then ContinueLoop If Number($sIsRelative) = 1 Then $sProfilePath = _PathFull( @AppDataDir & "\Mozilla\Firefox\" & StringReplace($sProfilePath, "/", "\") ) If NOT FileExists($sProfilePath & "\prefs.js") Then ContinueLoop $aResult[0][0] += 1 If $aResult[0][0] = UBound($aResult) Then Redim $aResult[ UBound($aResult) * 2][2] If Number(IniRead($sProfiles, $aSections[$i], "Default", "error")) = 1 Then $aResult[0][1] = $aResult[0][0] $aResult[ $aResult[0][0] ][0] = $sProfileName $aResult[ $aResult[0][0] ][1] = $sProfilePath EndIf Next If NOT $aResult[0][1] AND $aResult[0][0] > 0 Then $aResult[0][1] = 1 Redim $aResult [ $aResult[0][0] + 1 ][2] Return $aResult EndFunc1 point
-
How to exitloop without exiting the whole script.
232showtime reacted to sdfaheemuddin for a topic
Then #include<> Local $IsConnected=0 While 1 If $IsConnected<>_WinApi_IsInternetConnected() Then $IsConnected=_WinApi_IsInternetConnected() If $IsConnected = 0 Then MsgBox(0, "Alert!!!", "F566 Disconnected!!!") ElseIf $IsConnected = 1 Then MsgBox(0, "Alert!!!", "F566 Connected!!!") EndIf EndIf WEnd1 point