检查是否给出完整路径 [英] Check if full path given
本文介绍了检查是否给出完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以检查给定路径是否为完整路径?现在我正在这样做:
Is there a method to check if given path is full path? Right now im doing this:
if (template.Contains(":\\")) //full path already given
{
}
else //calculate the path from local assembly
{
}
但是必须有更优雅的方法来检查吗?
But there must be more elegant way for checking this?
推荐答案
尝试使用System.IO.Path.IsPathRooted
吗?它还为绝对路径返回true
.
Try using System.IO.Path.IsPathRooted
? It also returns true
for absolute paths.
System.IO.Path.IsPathRooted(@"c:\foo"); // true
System.IO.Path.IsPathRooted(@"\foo"); // true
System.IO.Path.IsPathRooted("foo"); // false
System.IO.Path.IsPathRooted(@"c:1\foo"); // surprisingly also true
System.IO.Path.GetFullPath(@"c:1\foo");// returns "[current working directory]\1\foo"
这篇关于检查是否给出完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文