Full path with double backslash (C#)

为君一笑 提交于 2019-11-27 03:24:39

问题


Is it possible to get a full path with double backslash by using Path.GetFullPath? Something like this:

C:\\Users\\Mammamia\\Videos\\Documents\\CFD\\geo_msh\\cubeOp.txt

instead of this:

C:\Users\Mammamia\Videos\Documents\CFD\geo_msh\cubeOp.txt

Or is there any other method?


回答1:


Do you mean this?

Path.GetFullPath(path).Replace(@"\", @"\\");



回答2:


C:\\Users\\Mammamia\\Videos\\Documents\\CFD\\geo_msh\\cubeOp.txt is not a valid path, so I'm not sure why you'd want it, but:

Path.GetFullPath(yourPath).Replace("\\", "\\\\");



回答3:


You can just do this:

Path.GetFullPath(@"C:\\Users\\Mammamia\\Videos\\Documents\\CFD\\geo_msh\\cubeOp.txt")

But i'm not sure why, you want to escape the \ ?

If yes, you can do just this :

 Path.GetFullPath(@"C:\Users\Mammamia\Videos\Documents\CFD\geo_msh\cubeOp.txt")



回答4:


I would recommend doing a String.replace(). I recently had to do this in a project for myself. So if you do something similar to:

String input = Path.GetFullPath(x);
input = input.Replace("\\","\\\\");

I am fairly confident that is what you need :)

Documentation: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx



来源:https://stackoverflow.com/questions/9294133/full-path-with-double-backslash-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!