[英]vb.net arguments / command line in application
I want to create my own command line.(as windows application, not prompt) Example: -f {filepath} -d {filename}
in textbox1 我想创建自己的命令行。(作为Windows应用程序,而不是提示符)示例:
-f {filepath} -d {filename}
in textbox1
-f C://Windows/Users/Myname/Documents -d junk.exe
so it must filter the filepath and filename so it becomes this my.computer.filesystem.delete("C://Windows/Users/Myname/Documents", "junk.exe")
因此它必须过滤文件路径和文件名,以便它成为此
my.computer.filesystem.delete("C://Windows/Users/Myname/Documents", "junk.exe")
thanks! 谢谢!
You can obtain your command line parameters this way: 您可以通过以下方式获取命令行参数:
Dim arguments As String() = Environment.GetCommandLineArgs()
I found this on MSDN. 我在MSDN上找到了这个。
You could use this function to get the value of your desired parameter (the parameter name must include the '-' sign.) 您可以使用此函数获取所需参数的值(参数名称必须包含“-”号。)
Public Function GetParameter(input As String, param As String) As String
Dim cmdargs As New List(Of String)
For Each item As Match In Regex.Matches(input, """(\\""|[^""])*?""|[^ ]+")
If item.ToString()(0) = """" And item.ToString()(item.ToString.Length - 1) = """" Then
cmdargs.Add(item.ToString().Remove(0, 1).Remove(item.ToString.Length - 2, 1))
Else
cmdargs.Add(item.ToString())
End If
Next
Return cmdargs(cmdargs.ToList().LastIndexOf(param) + 1)
End Function
If you use this function as GetParameter("-f")
and your command-line arguments are -f C://Windows/Users/Myname/Documents -d junk.exe
then you will get C://Windows/Users/Myname/Documents
as the output. 如果将此函数用作
GetParameter("-f")
并且命令行参数为-f C://Windows/Users/Myname/Documents -d junk.exe
那么您将获得C://Windows/Users/Myname/Documents
作为输出。 Now if your command line has a space, you could enclose it within double quotes to avoid it being interpreted as 'multiple arguments'. 现在,如果命令行中有空格,则可以将其用双引号引起来,以避免将其解释为“多个参数”。
Now in an event-handling method (maybe a button click), you can use :- 现在,在事件处理方法(可能是单击按钮)中,您可以使用:-
My.Computer.FileSystem.Delete(GetParameter(TextBox1.Text, "-f"), GetParameter(TextBox1.Text, "-d"))
... to get the job done. ...完成工作。 Hope it helps :-).
希望能帮助到你 :-)。 If you have questions, please comment below.
如有疑问,请在下面评论。 Updated
更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.