如何修剪相对路径 [英] How can I trim a Relative path
本文介绍了如何修剪相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何修剪动态相对路径.例如,我有以下路径:C:\ Users \ account.user \ Desktop \ attachment.pdf
因此,必须修剪C:\ Users \ account.user \ Desktop \.
在此先感谢!
Hi,
How can I trim a dynamical Relative Path. For Example, I''ve got this path: C:\Users\account.user\Desktop\attachment.pdf
So C:\Users\account.user\Desktop\ must be trimmed.
Thanks in advance!!
推荐答案
使用此处记录的路径类型来获取路径的目录部分: ^ ]和此 ^ ]来获取路径的文件名部分.
顺便说一句,您指定的路径不是相对路径,而是完全限定的路径.
只是说而已. :)
祝您编程愉快!
-MRB
Use the type Path like documented here to get the directory part of a path: http://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname(v=VS.71).aspx[^] and this http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=VS.71).aspx[^] to get the filename part of a path.
BTW the path you have specified is not a relative path but rather a fully qualified path.
Just saying. :)
Happy coding!
-MRB
这应该做到:
This should do it:
var path = "C:\Users\account.user\Desktop\attachment.pdf";
var relative = Path.GetFileName(path);
这篇关于如何修剪相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文