Hier noch eine kleines UDF um schnell Commandline Schalter abzufragen.
Ist mein erstes was ich veröffentliche hoffentlich sind die Angaben alle vollständig und Ihr versteht die Funktion
Bitte um Feedback
Spoiler anzeigen
;===============================================================================
;
; Function Name: _cmdline
; Description:: Fast find Comandline Switsches
; Parameter(s): [$Parameter = 0[,$Return = -1[,$count = 1[,$seperator = " "[,$array = 0]]]]]
; Return Value(s):
; On Success -
; $Parameter is Integer - Returns the X Commandline Switch
;
; $Parameter is String - Return True Switches exist | False not Exist
;
; $Return is set 0 or greather Return the next Switch Count by Found Switch
; Exapmle: test.exe -test "hello world" "I love AutoIT"
; _cmdline() return Count of Switches same $CmdLine[0]
; _cmdline(1) return First Switches same $CmdLine[1]
; _cmdline(4) return 0 and set @error = 2
; _cmdline("-test") return True
; _cmdline("-test2") return False
; _cmdline("-test",1) return "hello world"
; _cmdline("-test",1,2) return "hello world I love AutoIT"
; _cmdline("-test",1,2,"|") return "hello world|I love AutoIT"
; _cmdline("-test",1,2,"|",1) return a Array where Index 0 Count of Return Switsches
; _cmdline("-test",1,2,"|",2) return a Array ; disable the return the count in the first element
; Exapmle2: test.exe -Switch -x 2 -test "hello world" "I love AutoIT"
; _cmdline("-x",1) return "2"
; _cmdline("-x",0,2) return "-x 2"
;
; On Failure - Returns 0 and sets @error = 1 if Commandline Switches Count = 0; @error = 2 $Parameter is Integer and > Commandline Switches Count
; Author(s): Gummibaer ( [email='AutoIt@central-irc.de'][/email] )
;
;===============================================================================
;
Func _cmdline($Parameter = 0,$Return = -1,$count = 1,$seperator = " ",$array = 0)
If IsInt($Parameter) And $Parameter = 0 Then Return $CmdLine[0]
If $CmdLine[0] = 0 Then Return SetError(1, 0, 0)
If IsInt($Parameter) Then
If $Parameter > $CmdLine[0] Then SetError(2, 0, 0)
Return $CmdLine[$Parameter]
EndIf
For $i = 1 To $CmdLine[0] Step 1
If $Parameter = $CmdLine[$i] Then
If IsInt($Return) And $Return >= 0 Then
If IsInt($count) And $count > 0 Then
Local $sLine
$count -= 1
For $x = 0 To $count Step 1
If $i+$Return+$x <= $CmdLine[0] Then
$sLine &= $CmdLine[$i+$Return+$x]&$seperator
EndIf
Next
$sLine = StringTrimRight($sLine,1)
If $array = 1 Then Return StringSplit($sLine, $seperator, 0)
If $array = 2 Then Return StringSplit($sLine, $seperator, 2)
Return $sLine
EndIf
Return $CmdLine[$i+$Return]
EndIf
Return True
EndIf
Next
Return False
EndFunc
;===============================================================================
;
; Function Name: _cmdlinefind
; Description:: Find Comandline Switsches
; Parameter(s): [$findstring = ""[,$Return = 0}]
; Return Value(s):
; On Success -
; $findstring is Integer - Returns the X Commandline Switch
;
; $Parameter is String - Return True Switches exist | False not Exist
;
; $Return is set 0 or greather Return the next Switch Count by Found Switch
; Exapmle: test.exe -switsch -test523 -key
; _cmdlinefind("-test") return 2 ;the Number where $findstring was found
; _cmdline("-test",1) return "-test523" ;the fulltext
;
; On Failure - Returns 0 and sets @error = 1 if Commandline Switches Count = 0; @error = 2 $findstring is empty
; Author(s): Gummibaer ( [email='AutoIt@central-irc.de'][/email] )
;
;===============================================================================
Func _cmdlinefind($findstring = "",$Return = 0)
If $CmdLine[0] = 0 Then Return SetError(1, 0, 0)
If $findstring = "" Then Return SetError(2, 0, 0)
For $i = 1 To $CmdLine[0] Step 1
If StringInStr($CmdLine[$i],$findstring) Then
If $Return = 0 Then Return $i
Return $CmdLine[$i]
EndIf
Next
Return False
EndFunc