Modify ↓
Opened 2 years ago
Last modified 8 months ago
#3892 assigned Feature Request
Func() Pass Parameter Bynames
Reported by: | Jpm | Owned by: | Jon |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | Severity: | None | |
Keywords: | Cc: |
Description (last modified by mLipok)
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 Changed 2 years ago by Jpm
- Owner set to Jpm
- Status changed from new to assigned
comment:2 Changed 2 years ago by mLipok
- Description modified (diff)
comment:3 Changed 8 months ago by Jpm
- Owner changed from Jpm to Jon
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Note: See
TracTickets for help on using
tickets.
Fix sent to Jon