Modify ↓
Opened on Jun 1, 2022 at 6:37:56 PM
Last modified on Mar 17, 2024 at 4:05:45 PM
#3892 assigned Feature Request
Func() Pass Parameter Bynames
| Reported by: | J-Paul Mesnage | Owned by: | Jon |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | Cc: |
Description (last modified by )
Instead of skipping parameter not need using a Default keyword
the Func() syntax can be
Func functioname ( [ [Const] [ByRef] $param1, ... ,] [ [ByNames] [ByRef] $optionalpar1 = value, ... ] )
so the function can be for _PathSplit()
#include <Array.au3> #include <File.au3> ;read in an array only Local $aPathSplit = _PathSplit_ByNames(@ScriptFullPath) ; , $sDrive, $sDir, $sFileName, $sExtension) _ArrayDisplay($aPathSplit, "_PathSplit_ByNames of " & @ScriptFullPath) ; read just the folder part Local $sFolder = "" _PathSplit_ByNames(@ScriptFullPath, sDir = $sFolder) MsgBox(0, "Folder", $sFolder) Func _PathSplit_ByNames($sFilePath, BYNAMES ByRef $sDrive = ByDefault, ByRef $sDir = ByDefault, ByRef $sFileName = ByDefault, ByRef $sExtension = ByDefault) Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH) If @error Then ; This error should never happen. ReDim $aArray[5] $aArray[$PATH_ORIGINAL] = $sFilePath EndIf Local $KEYWORD_BYDEFAULT = 3 ; if AutoItConstants.au3 is not updated If IsKeyWord($sDrive) <> $KEYWORD_BYDEFAULT Then $sDrive = $aArray[$PATH_DRIVE] Local $sTemp If StringLeft($aArray[$PATH_DIRECTORY], 1) == "/" Then $sTemp = StringRegExpReplace($aArray[$PATH_DIRECTORY], "\h*[\/\\]+\h*", "\/") Else $sTemp = StringRegExpReplace($aArray[$PATH_DIRECTORY], "\h*[\/\\]+\h*", "\\") EndIf $aArray[$PATH_DIRECTORY] = $sTemp If IsKeyWord($sDir) <> $KEYWORD_BYDEFAULT Then $sDir = $sTemp If IsKeyWord($sFileName) <> $KEYWORD_BYDEFAULT Then $sFileName = $aArray[$PATH_FILENAME] If IsKeyWord($sExtension) <> $KEYWORD_BYDEFAULT Then $sExtension = $aArray[$PATH_EXTENSION] Return $aArray EndFunc ;==>_PathSplit_ByNames
a ByDefault keyword is also usefull if the caller calling with Default is to be handled differently than an parameter being optional
Attachments (0)
Change History (3)
comment:1 by , on Jun 1, 2022 at 6:38:22 PM
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , on Jun 2, 2022 at 11:10:13 AM
| Description: | modified (diff) |
|---|
comment:3 by , on Mar 17, 2024 at 4:05:45 PM
| Owner: | changed from to |
|---|
Note:
See TracTickets
for help on using tickets.

Fix sent to Jon