c# - 使用 C# 为 cmd 转义反斜杠
问题描述
我有一个问题,我正在使用 FileBrowserDialog 来获取一些文件夹路由。但这给了我这样的路线: D:\\Angel\\Desktop\\DWServicio
我的问题是:我必须从我的应用程序运行 windows 命令,例如我必须运行这个:dir D:\Angel\Desktop\DWServicio / b / s > .\archivo.txt
但是当我使用 FileBrowserDialog 我的代码行是: dir D:\\Angel\\Desktop\\DWServicio / b / s > .\archivo.txt
所以,我只需要逃避 \\ 并得到 \
在我的代码中:我试图使用替换来逃避,例如:
exe.ExecuteCommandSync(command.Replace(@"\\", @"\"));
或者:
exe.ExecuteCommandSync(command.Replace("\\", @"\"));
等等
但是当我调试结果是一样的: D:\\Angel\\Desktop\\DWServicio
如果我执行这个:
command = @"dir D:\Digital_Solutions / b / s > d:\archivo.txt";
exe.ExecuteCommandSync(command);
完美运行,我的问题是当我尝试使用 FileBrowserDialog 路径时
也许有人可以帮助我吗?提前致谢。
问候
解决方案
您是否尝试过使用 /'s 代替?
快速尝试此代码:
string str = "D:\\Angel\\Desktop\\DWServicio";
Console.WriteLine(str.Replace("\\","/"));
返回 D:/Angel/Desktop/DWServicio
这取决于您的需要可以工作。
推荐阅读
- python - 在远程计算机上训练模型时,如何在本地使用 Tensorboard?
- java - 如何在Java中将数组放入数组的ArrayList
- php - 从 Android 向 php 服务器发送数据
- javascript - 通过数组创建多个模态
- python - 用 USB 连接函数发生器和计算机
- java - 使用 Inflator 而不是 ZipInputStream 从 zip 文件中提取数据
- amazon-web-services - 如何对 AWS 负载均衡器进行 sftp 和 https 以进行文件传输?
- javascript -
出现在页面上。如何隐藏它? - cv2 - 如何使用opencv获取图像中组件的周长?
- python - 使用 boto3 检查是否仍有任何文件需要上传到 Amazon S3