我想创建自己的命令行。(作为windows应用程序,不提示(示例:文本框1 中的-f {filepath} -d {filename}
-f C://Windows/Users/Myname/Documents -d junk.exe
因此它必须过滤文件路径和文件名所以它变成了这个my.computer.filesystem.delete("C://Windows/Users/Myname/Documents", "junk.exe")
谢谢!
您可以使用此函数来获取所需参数的值(参数名称必须包含'-'号。(
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
如果将此函数用作GetParameter("-f")
,并且命令行参数为-f C://Windows/Users/Myname/Documents -d junk.exe
,那么您将得到C://Windows/Users/Myname/Documents
作为输出。现在,如果您的命令行有空格,您可以将其括在双引号内,以避免将其解释为"多个参数"。
现在,在事件处理方法中(可能是单击按钮(,您可以使用:-
My.Computer.FileSystem.Delete(GetParameter(TextBox1.Text, "-f"), GetParameter(TextBox1.Text, "-d"))
完成工作。希望能有所帮助:-(。如果你有问题,请在下面评论已更新
您可以通过以下方式获取命令行参数:
Dim arguments As String() = Environment.GetCommandLineArgs()
我在MSDN上找到了这个。