检查是否给出完整路径

编程入门 行业动态 更新时间:2024-10-24 16:30:50
本文介绍了检查是否给出完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以检查给定路径是否为完整路径?现在我正在这样做:

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"

更多推荐

检查是否给出完整路径

本文发布于:2023-11-30 05:35:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648899.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   完整

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!