Hello Me You Posted October 4, 2006 Share Posted October 4, 2006 (edited) Hello all, given typical command lines like "C:\Program Files\Company\Product\bin\executable.exe /command line parameters" "\Program Files\Company\Product\bin\executable.exe /command line parameters" "..\..\..\Program Files\Company\Product\bin\executable.exe /command line parameters" ".\bin\executable.exe /command line parameters" "executable /command line parameters" [...], how Do you determine the path, filename and command line parameter portions with reliability? Thanks in advance! P. S.: I've tried the search function with "+path +filename +parameter". It only gave an error since the search terms seem to be to short. Edit: Sorry for the broken topic line. Seems I can't complete it retroactively. Edited October 4, 2006 by Hello Me You Random Link to comment Share on other sites More sharing options...
jvanegmond Posted October 4, 2006 Share Posted October 4, 2006 I know the function _PathSplit can help you on your way. But I can't find any more information about it, it's bad. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 4, 2006 Share Posted October 4, 2006 Hi, try this: ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\loctus.exe"')&@LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\loctus.exe /c /tray"')&@LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\eyeballs_exp.exe /slow -rate 800"')&@LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Company\Product\bin\executable.exe /command line parameters"')&@LF) ConsoleWrite(_StringRemoveBounding('"\Program Files\Company\Product\bin\executable.exe /command line parameters"')&@LF) ConsoleWrite(_StringRemoveBounding('"..\..\..\Program Files\Company\Product\bin\executable.exe /command line parameters"')&@LF) ConsoleWrite(_StringRemoveBounding('".\bin\executable.exe /command line parameters"')&@LF) ConsoleWrite(_StringRemoveBounding('"executable /command line parameters"')&@LF) #include<Array.au3> Func _StringRemoveBounding($s_Filename) Local $c = StringReplace($s_Filename, '"' & "'" & "''", '') Local $a = StringSplit($c, "\") If StringInStr($a[$a[0]], " ") <> 0 Then Local $b = StringLeft($a[$a[0]], StringInStr($a[$a[0]], " ")) Else Return $s_Filename EndIf return $b EndFunc Func _StringRemoveBounding1($Str,$Opt=1) Local $StrRep,$StrFix,$chk If StringRegExp ($Str, '"') = 1 Then $StrFix = StringTrimRight(StringTrimLeft(StringReplace($Str,'"' & '"', ''),1),1) If StringRegExp ($Str, '/') = 1 Then $chk = StringSplit($StrFix , '/') $StrRep = $chk[UBound($chk) - 1] $StrFix = StringReplace($StrFix,$StrRep,'') EndIf Else $StrFix = $Str EndIf If Not @Error Then Return $StrFix EndFunc So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Hello Me You Posted October 4, 2006 Author Share Posted October 4, 2006 I know the function _PathSplit can help you on your way. But I can't find any more information about it, it's bad.Thanks for your fast reply! I quickly checked the source for _PathSplit and it seems that it doesn't take possible command line parameters into account. What it does for separating filename and path is simply checking every single character (starting from the right end of the string) if it is "\" or "/". The first occurance is taken as the split point between filename and path.I need to separate path, filename AND command line parameters reliably... even for strings as nasty as "..\..\..\test\test test\test-test\program -program.exe /c:\path". How does the cmd.exe do it? Random Link to comment Share on other sites More sharing options...
jvanegmond Posted October 4, 2006 Share Posted October 4, 2006 Use _PathSplit first. Then use a StringSplit on the filename, and voila.. command line parameters role out like round-things! Need any further help writing this? github.com/jvanegmond Link to comment Share on other sites More sharing options...
Hello Me You Posted October 4, 2006 Author Share Posted October 4, 2006 Use _PathSplit first. Then use a StringSplit on the filename, and voila.. command line parameters role out like round-things!Need any further help writing this?Any help is greatly appreciated. If I'd use _PathSplit on the complete string at first, it'd try to take the command line parameters as the the filename. For my last example "..\..\..\test\test test\test-test\program -program.exe /c:\path", it would return "path" as the filename and "\..\..\test\test test\test-test\program -program.exe /c:\" as the path. Neither is correct. Random Link to comment Share on other sites More sharing options...
Valik Posted October 5, 2006 Share Posted October 5, 2006 Manadar, I assure you that will not work. _PathSplit() is for PATHS, not for command line strings. 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