简体   繁体   English

通过命令行将带有空格的2个文件路径传递给C#应用程序

[英]Passing 2 filepaths with spaces via commandline to a C# application

I am trying to pass two directory paths via the command line to a C# application. 我试图通过命令行将两个目录路径传递给C#应用程序。 These paths will likely contain spaces, and given that C# populates args[] by splitting across spaces, this is giving me problems. 这些路径可能包含空格,并且考虑到C#通过拆分空格来填充args[] ,这给我带来了问题。

What I tried was passing the paths wrapped in quotes, like this: 我尝试的是传递用引号引起来的路径,如下所示:

myprogram.exe "C:\aa a\bbb\" "C:\ppp\ll l\"

..this, however, creates a problem because the backslash at the end of each path is being interpreted by C# as an escape character, so it is parsing the double quote as well. 但是,这会产生问题,因为C#将每个路径末尾的反斜杠解释为转义字符,因此它也解析了双引号。 When I run the app with these argurments, args[] contains only one entry: 当我使用这些参数运行应用程序时,args []仅包含一个条目:

C:\aa a\bbb" C:\ppp\ll l"

The easy solution would be to only enter directory paths without the final backslash, but it is not optimal and will likely frustrate users of the program. 一种简单的解决方案是仅输入目录路径而没有最后的反斜杠,但这不是最佳选择,并且可能会使程序用户感到沮丧。

Is there an easy solution to this? 有一个简单的解决方案吗?

您是否尝试过将它们“扭曲”?

myprogram.exe "C:\\aa a\\bbb\\" "C:\\ppp\\ll l\\"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM